Reputation: 478
I have plotted my data as a scatter bar plot and have a benchmark (Basemodel) and a theoretical value (AASHTO) that I am presenting with different colored points. I use the following code and my graph looks as follows:
library(ggplot2)
ggplot(data = plotshear, aes(x = Shear, y = LLDF)) + geom_jitter(aes(colour = Source))
# plotshear data:
Source Shear LLDF
# 1 Baseline EXT.Single 0.7627894
# 2 Samples EXT.Single 0.7130376
# 3 Baseline EXT.Multi 0.8521338
# 4 Samples EXT.Multi 0.7975502
# 5 Baseline INT.Single 0.5706947
# 6 Samples INT.Single 0.5462812
# 7 Baseline INT.Multi 0.7291602
# 8 Samples INT.Multi 0.7331171
# 9 AASHTO EXT.Multi 0.8250000
# 10 AASHTO INT.Single 0.7200000
# 11 AASHTO INT.Multi 0.8840000
I actually need a error bar for a mean looking like this:
current plot
plot needed
Upvotes: 1
Views: 799
Reputation: 525
Here is a solution that reproduces the "plot needed" figure from your data:
library(ggplot2)
# plotshear data:
plotshear <- data.frame(Source = c(rep(c("Baseline", "Samples"), 4), rep("AASHTO", 3)),
Shear = c(rep("EXT.Single", 2), rep("EXT.Multi", 2), rep("INT.Single", 2),
rep("INT.Multi", 3), "INT.Single", "INT.Multi"),
LLDF = c(0.7627894, 0.7130376, 0.8521338, 0.7975502, 0.5706947,
0.5462812, 0.7291602, 0.7331171, 0.8250000, 0.7200000, 0.8840000))
#without error bars
ggplot(data = plotshear, aes(x = Shear, y = LLDF)) +
geom_boxplot() +
geom_jitter(aes(color = Source)) +
stat_summary(fun.y=mean, geom="point", shape=23, size=4) +
stat_summary(fun.y=mean, geom="line", aes(group=1))
#with error bars
ggplot(data = plotshear, aes(x = Shear, y = LLDF)) +
geom_boxplot() +
geom_jitter(aes(color = Source)) +
stat_summary(fun.y=mean, geom="point", shape=23, size=4) +
stat_summary(fun.y=mean, geom="line", aes(group=1)) +
stat_summary(fun.data = mean_se, geom = "errorbar")
Upvotes: 3