I\'d like to do the following plot using ggplot:
Here is an
I suppose that sample data frame you provided isn't build in appropriate way because all values in group1
have class
1
, and in group2
all are class 2
. So I made new data frame, added also new column named replicate
that shows number of replicate (four replicates (with two class
values) in each group
).
example.df = data.frame(mean = c(0.3,0.8,0.4,0.65,0.28,0.91,0.35,0.61,0.32,0.94,0.1,
0.9,0.13,0.85,0.7,1.3),
std.dev = c(0.01,0.03,0.023,0.031,0.01,0.012,0.015,0.021,0.21,
0.13,0.023,0.051,0.07,0.012,0.025,0.058),
class = c("1","2","1","2","1","2","1","2","1","2","1",
"2","1","2","1","2"),
group = rep(c("group1","group2"),each=8),
replicate=rep(rep(1:4,each=2),time=2))
Now you can use geom_pointrange()
to get points with confidence intervals and facet_wrap()
to make plot for each group.
ggplot(example.df,aes(factor(replicate),
y=mean,ymin=mean-2*std.dev,ymax=mean+2*std.dev,color=factor(class)))+
geom_pointrange()+facet_wrap(~group)