Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

order stat_compare_means #12

Closed
RoKant opened this issue Jul 19, 2017 · 2 comments
Closed

order stat_compare_means #12

RoKant opened this issue Jul 19, 2017 · 2 comments

Comments

@RoKant
Copy link

RoKant commented Jul 19, 2017

Hi Kassambara,

I would really like to use stat_compare_means to display the significance levels of my dataset.
The only thing I can't seem to fix is the order of the labels, ggplot keeps these factor levels nice in order, but your function does not keep this order.
It might be a variable I completely missed, but I have not found a solution in the last 3 days.

p1<- ggplot(data=subsetChain, aes(x=Chothia,y=total.energy))+
geom_boxplot(aes(fill=LCtype),outlier.shape=NA,notch=TRUE)+theme_bw()+
stat_compare_means(aes(group = LCtype), label = "p.signif",geom="label")+
scale_y_continuous(limits=c(-5,5))+ ylab("Total energy (kcal/Mol)")+
theme(axis.title.x=element_blank(),legend.position=c(0.01,0.9))

I have the levels of the dataset properly ordered, ggplot keeps the levels in order, but the labeling of your function does not keep the order, resulting in wrong significance levels, it seems to order the factors alphabettically.

Is that something I can easily fix, or is there a line in your code where the labels are reordered?

Cheers,

Rob van der Kant

@RoKant
Copy link
Author

RoKant commented Jul 19, 2017

found a solution:

signifs <- compare_means(total.energy~LCtype,data=subsetChain,group.by = "Chothia")
#reorder rows
signifs <- signifs[match(chotL,signifs$Chothia),]

#plot significance using geom_text
p1<-ggplot(data=subsetChain,aes(x=Chothia,y=total.energy))+
geom_boxplot(aes(fill=LCtype),outlier.shape=NA,notch=TRUE)+theme_bw()+
geom_text(data=signifs,aes(y=5,label=p.signif,x=Chothia))+
scale_y_continuous(limits=c(-5,5))+
ylab("Total energy (kcal/Mol)")+
theme(axis.title.x=element_blank(),legend.position=c(0.01,0.9))

@kassambara
Copy link
Owner

Thank you for pointing this out. Fixed now, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants