【发布时间】:2017-01-11 11:10:28
【问题描述】:
link 中的第一个图展示了如何可视化标准误差的一个非常好的示例,我想在 R 中复制它。
我带着下面的东西到达那里
set.seed(1)
pop<-rnorm(1000,175,10)
mean(pop)
hist(pop)
#-------------------------------------------
# Plotting Standard Error for small Samples
#-------------------------------------------
smallSample <- replicate(10,sample(pop,3,replace=TRUE)) ; smallSample
smallMeans<-colMeans(smallSample)
par(mfrow=c(1,2))
x<-c(1:10)
plot(x,smallMeans,ylab="",xlab = "",pch=16,ylim = c(150,200))
abline(h=mean(pop))
#-------------------------------------------
# Plotting Standard Error for Large Samples
#-------------------------------------------
largeSample <- replicate(10,sample(pop,20,replace=TRUE))
largeMeans<-colMeans(largeSample)
x<-c(1:10)
plot(x,largeMeans,ylab="",xlab = "",pch=16,ylim = c(150,200))
abline(h=mean(pop))
但我不确定如何绘制带有 X 符号的原始数据。谢谢。
【问题讨论】:
-
试试
ggplot2包。一个基本的应该是ggplot(data.frame(x, smallMeans), aes(x=x, y = smallMeans))+geom_point()+geom_line()+geom_hline(yintercept = mean(pop)) -
感谢您的回复。这与我到目前为止所做的很接近(请参阅更新的代码),但我希望能够覆盖原始数据点
标签: r plot standard-error