Plotting summary statistics in ggplot2

2019-07-23 07:47发布

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?

标签: r ggplot2
1条回答
做个烂人
2楼-- · 2019-07-23 08:30

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))
查看更多
登录 后发表回答