Make a box-plot with jittered points for multiple groups using ggplot2
Let me demonstrate it with an example. Use the
ToothGrowth
data set in the ggplot2
librarylibrary(ggplot2)
ggplot(ToothGrowth, aes(x=as.factor(dose), y=len, color=supp)) +
geom_boxplot(position=position_dodge(0.9))+
geom_jitter(position=position_dodge(0.9)) +
xlab("dose")
I want to make the points separate from each other rather than on the same vertical line.
ggplot(ToothGrowth, aes(x= as.factor(dose), y=len, color= supp,fill= supp)) +
geom_point(position=position_jitterdodge(dodge.width=0.9)) +
geom_boxplot(fill="white", alpha=0.1, outlier.colour = NA,
position = position_dodge(width=0.9)) +
xlab("dose")
Thanks for the sharing. The picture is vivid.
ReplyDeleteCreative BioMart