r - How to label the barplot in ggplot with the labels in another test result? -
i label plot label output of test, eg., lsd test output (a, b, ab, etc) using lsd.test in library agricolae. here running example.
library(ggplot2) library(agricolae) wt<-gl(3,4,108,labels=c("w30","w60","w90")) pl<-gl(3,12,108,labels=c("p0","p1","p2")) gp<-gl(3,36,108,labels=c("a","b","c")) dat<-cbind( a=runif(108), b=runif(108,min=1,max=10), c=runif(108,min=100,max=200), d=runif(108,min=1000,max=1500) ) dat.df<-data.frame(wt,pl,gp,dat) dat.m<-melt(dat.df) ggplot(dat.m,aes(x=wt,y=value,group=pl,facet=gp,fill=pl))+ stat_summary(fun.y=mean,geom="bar",size=2,position="dodge")+ stat_summary(fun.ymin=function(x)(mean(x)-sd(x)/sqrt(length(x))),geom="errorbar", fun.ymax=function(x)(mean(x)+sd(x)/sqrt(length(x))),position="dodge")+ facet_grid(variable~facet,scale="free_y")+ opts(legend.position="top")+ scale_colour_manual(values = c("red", "blue", "green"))
normally, in other library, tested data, , pass label text plot, possible in ggplot? eg., in stat_summary(), use lsd.test within fun.y?
to achieve this, have create label layer using geom_text
, specify own dataset.
expanding on example in lsd.test
in package agricolae
:
library(agricolae) library(ggplot2) data(sweetpotato) model <- aov(yield~virus, data=sweetpotato) lsd <- lsd.test(model,"virus",p.adj="bon") ggplot() + stat_summary(data=sweetpotato, aes(x=virus, y=yield), fun.y=mean, geom="bar") + geom_text(data=lsd, aes(x=trt, y=means, label=round(means, 1)), vjust=0)
Comments
Post a Comment