Hello,
I am plotting a boxplot using ggplot2, with annotation using annotate() (see below). I wanted to order the Boxplot by means, using reorder in aes(), but it didn't work. I noticed it worked when I remove the annotations part (I guess since the annotations creates a new x value, it takes in into account when calculating the means the problems comes from there)
Anyone has a solution to this issue?
p_thymus <- ggplot(thymus, aes(x=reorder(Cell_id,-norm_intden,mean,na.rm=TRUE), y=norm_intden))+
geom_boxplot(alpha=0.6, fill="#E6E6FA")+
ggtitle("Thymus")+
theme_bw()+
labs(x="", y="normalised integrated fluorescence density, log10 scale")+
geom_hline(yintercept = division_cycle, linetype = 2, colour = "red", size=0.5)+
expand_limits(y=1)+
scale_y_log10()+
theme(axis.text.x= element_text(size=25))+
theme(title=element_text(size=25))+
theme(axis.text.y= element_text(size=24))+
theme(axis.title.y = element_text(vjust = 1.8, size=20))+
scale_fill_viridis(discrete = TRUE)+
stat_summary(fun=mean,geom="point")+
annotate("text", x = "", y = 0.45, label = "1st division", size=7)+
annotate("text", x = "", y = 0.225, label = "2nd division", size=7)+
annotate("text", x = "", y = 0.1125, label = "3rd division", size=7)+
annotate("text", x = "", y = 0.05625, label = "4th division", size=7)+
annotate("text", x = "", y = 0.028125, label = "5th division", size=7)+
annotate("text", x = "", y = 0.0140625, label = "6th division", size=7)+
annotate("text", x = "", y = 0.00703125, label = "7th division", size=7)+
annotate("text", x = "", y = 0.003515625, label = "8th division", size=7)
p_thymus
thanks a lot!