Is there a way to plot summary statistics in ggplot2 without the raw data? Say I have three data points: the first has mean 34.2 and standard error 3.4, the second has mean 28.6 and standard error 0.5, and the third has mean 44.0 and standard error 2.2. How would I plot this?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
There may be more efficient ways, but you could try putting those numbers into a data frame and plotting from that. So you'd have observations 1 - 3, and their corresponding means and standard errors in three columns as follows:
obs <- c(1,2,3)
mean <- c(34.2, 28.6, 44.0)
se <- c(3.4, 0.5, 2.2)
df = data.frame(obs, mean, se)
ggplot(df, aes(y=mean, x=obs)) +
geom_bar(position="dodge", stat="identity") +
geom_errorbar(aes(ymax = mean+se, ymin = mean-se))