r - ggplot2 & stat_ellipse: Draw ellipses around multiple groups of points -


this might simple one, i'm trying draw ellipses around treatments on pcoa plot.

my data frame (sc) is:

             mds1        mds2 treatment x1xf1 -0.19736183 -0.24299825   1xflood x1xf2 -0.17409568 -0.29727596   1xflood x1xf3 -0.15272444 -0.28553837   1xflood s1    -0.06643271  0.47049959     start s2    -0.15143350  0.31152966     start s3    -0.26156297  0.12296849     start x3xf1  0.29840827  0.04581617  3xfloods x3xf2  0.50503749 -0.07011503  3xfloods x3xf3  0.20016537 -0.05488630  3xfloods 

and code is:

ggplot(data=sc,(aes(x=mds1,y=mds2,colour = treatment)))+geom_point(size=3)+   ggtitle("pcoa of samples @ 'class' level(method='bray')\n",sep=''))+   theme_bw()+guides(colour = guide_legend(override.aes = list(size=3)))+   stat_ellipse() 

it plots pcoa okay until stat_ellipse(). i've tried various parameters , @ best can 1 ellipse whole plot (although can't seem reproduce now).

what i'm after 3 ci ellipses 3 treatments, coloured same treatments. appreciated!

thanks.

there no stat_ellipse(...) in ggplot package, must have retreived somewhere else. care share?? there @ least 2 versions aware of, here, , here. neither of these seem work dataset, odd because both have worked other datasets.

i fell on option of generating ellipses externally ggplot, not difficult really.

library(ggplot2) library(ellipse) centroids <- aggregate(cbind(mds1,mds2)~treatment,sc,mean) conf.rgn  <- do.call(rbind,lapply(unique(sc$treatment),function(t)   data.frame(treatment=as.character(t),              ellipse(cov(sc[sc$treatment==t,1:2]),                      centre=as.matrix(centroids[t,2:3]),                      level=0.95),              stringsasfactors=false)))  ggplot(data=sc,(aes(x=mds1,y=mds2,colour = treatment)))+   geom_point(size=3)+   geom_path(data=conf.rgn)+   ggtitle(paste("pcoa of samples @ 'class' level(method='bray')\n",sep=''))+   theme_bw()+   guides(colour = guide_legend(override.aes = list(size=3))) 

Comments

Popular posts from this blog

C# random value from dictionary and tuple -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -