Hi there,
I would like to create black outlines around my errorbars in order to get especially the white errorbar better visible.
Is that even possible with ggplot2 and if yes how?
I would be very grateful if anyone could help me. I added my code and a dput() of my data,
Thank you very much,
Michael
#my code:--------------------------------------------------
#load packages
library(compute.es<http://compute.es/>);library(ggplot2);library(multcomp);library(pastecs);library(WRS)
library(pastecs);library(Hmisc)
library (car)
# Comput CI manually and produce error plots
#CI manually computed with formula summarySE
summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE,
conf.interval=.95, .drop=TRUE) {
library(plyr)
# New version of length which can handle NA's: if na.rm==T, don't count them
length2 <- function (x, na.rm=FALSE) {
if (na.rm) sum(!is.na<http://is.na/>(x))
else length(x)
}
# This does the summary. For each group's data frame, return a vector with
# N, mean, and sd
datac <- ddply(data, groupvars, .drop=.drop,
.fun = function(xx, col) {
c(N = length2(xx[[col]], na.rm=na.rm),
mean = mean (xx[[col]], na.rm=na.rm),
sd = sd (xx[[col]], na.rm=na.rm)
)
},
measurevar
)
# Rename the "mean" column
datac <- rename(datac, c("mean" = measurevar))
datac$se <- datac$sd / sqrt(datac$N) # Calculate standard error of the mean
# Confidence interval multiplier for standard error
# Calculate t-statistic for confidence interval:
# e.g., if conf.interval is .95, use .975 (above/below), and use df=N-1
ciMult <- qt(conf.interval/2 + .5, datac$N-1)
datac$ci <- datac$se * ciMult
return(datac)
}
#summarySE provides the standard deviation, standard error of the mean, and a (default 95%) confidence interval
CI <- summarySE(data, measurevar="cor_average", groupvars=c("damage","leaf"))
CI
#plotting in ggplot
# To prevent that errorbars overlap use position_dodge to move them horizontally
pd <- position_dodge(0.4) # move them .05 to the left and right
#Create errorbar using 95% CI
ggplot(CI, aes(x=leaf, y=cor_average, colour=damage)) +
geom_errorbar(aes(ymin=cor_average-ci, ymax=cor_average+ci), width=.3, size=1,position=pd) +
geom_line(position=pd) +
scale_colour_manual(values=c("white","black","gray65"))+
geom_point(position=pd,size=3)
#my data set: ---------------------------------------------------------------------------------------------------------------