I would like to add lines between \"mean\" in my boxplot.
My code:
library(ggplot2)
library(ggthemes)
Gp=factor(c(rep(\"G1\",80),rep(\"G2\",80)))
Fc=fac
I have a way of doing this, surely similar to whats have been done, but using geom_line
and position_dodge
and data.table
library(data.table)
DATA=data.table(Y,X,Z,Fc,Gp)
qplot(X, Y, data=DATA, geom="boxplot", fill=Z, na.rm = TRUE,
outlier.size = NA, outlier.colour = NA) +
geom_line(data = DATA[,list(Y = mean(Y)), by = .(X,Z,Fc,Gp)][X == "B1"],aes(X,Y,color = Z),group =1, position = position_dodge(width = .75),color = "black") +
geom_line(data = DATA[,list(Y = mean(Y)), by = .(X,Z,Fc,Gp)][X == "B2"],aes(X,Y,color = Z),group =1, position = position_dodge(width = .75),color = "black") +
facet_grid(Gp ~ Fc)+ theme_light()+
theme(legend.position="bottom") +
stat_summary(fun.y=mean, geom="point", shape=23, position = position_dodge(width = .75))