在ggplot2中绘制摘要统计信息 [英] Plotting summary statistics in ggplot2
问题描述
有没有一种方法可以在没有原始数据的情况下在ggplot2中绘制摘要统计信息?假设我有三个数据点:第一个数据具有平均值34.2和标准误3.4,第二个数据具有平均值28.6和标准误0.5,第三个数据具有平均值44.0和标准误2.2.我将如何绘制?
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-3,以及它们的相应平均值和标准误差:
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))
这篇关于在ggplot2中绘制摘要统计信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!