error <- function(x)(qt(0.975,df=length(x)-1)*sd(x)/sqrt(length(x)))
ggplot(Plants.means,aes(x=Treat, y=Yield, colour=rootpatH, group=rootpatH)) +
geom_errorbar(aes(ymin=Yield-error(Plants.means$Yield),ymax=Yield+error(Plants.means$Yield)), colour="black",width=.1, position=pd) +
geom_point(position=pd, size=4)
Adding Error Bars in R with ggplot
Question
I would like to make a plot in R plotting two categorical variables (treat) by LWP.
I would like to change the color of the dots (the fill) to correspond with the variable rootpatH (one dot in each treatment).
I would also like to add a notation if the differences are significant or not..
Plants.means<-aggregate(Plants[10:44],Plants[c(6,9)],mean,na.rm=TRUE)
SE<-function(x)(sd(x,na.rm=TRUE)/ (length(x)-sum(is.na(x)))^0.5)
ggplot(Plants.means, aes(x=Treat, y=Yield, group=1)) +
geom_errorbar(width=.1, aes(ymin=Yield-SE(Plants.means$Yield), ymax=Yield+SE(Plants.means$Yield))) +
geom_point(shape=21, size=3, fill="white") +
ylim(0,1750)
I also want to change the error bars to represent 95% CI instead of SE.
Treat is categorical rootpatH is categorical LWP_meas2 is continuous
Solution 2
OTHER TIPS
As Ben says you probably want something like this (of necessity not tested since no data was offered:
with( Plants.means,
errbar(x =Treat, y = LWP_Meas2,
yplus = LWP_Meas2 + SE( LWP_Meas2),
yminus = LWP_Meas2 - SE( LWP_Meas2),
add=T,na.rm=TRUE, col=c("blue", "hotpink"))
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow