I have four factors for a continuous time variable along with its confidence interval. I would like to produce a publication quality error bar chart that is clear to understand. For now, I used colors, x axis position, facets and alpha level to distinguish them.
N = 32
df<- data.frame(gender=gl(2,1,N, c("male","female")),
direction=gl(2,2,N, c("up","down")),
condition=gl(4,4,N, c("c1","c2","c3","c4")),
location=gl(2,16,N, c("east","west")),
t=rnorm(N, 1, 0.5),
ci=abs(rnorm(N, 0, 0.2)))
pp <-
ggplot(df, aes(x=gender, y=t, fill=condition, alpha=direction)) +
facet_grid(location~.) +
geom_bar(position=position_dodge(.9), stat="identity", color="black") +
geom_errorbar(aes(ymin=t-ci, ymax=t+ci),
width=.2, # Width of the error bars
position=position_dodge(.9)) +
scale_alpha_discrete(range= c(0.4, 1))
pp
In the attachment, I have added the output figure, while manually editing the SVG file to make the lower-left group of bars to make them as I wanted. (The spacing in between each pair is not necessarily required.)