1
我正在尋找一種繪製人口比例隨時間變化的數據的方法,其中顯示邊距或誤差,類似於此示例:http://goo.gl/dbrbu。但是找不到任何說明。謝謝!如何在R中創建具有誤差範圍的折線圖
我正在尋找一種繪製人口比例隨時間變化的數據的方法,其中顯示邊距或誤差,類似於此示例:http://goo.gl/dbrbu。但是找不到任何說明。謝謝!如何在R中創建具有誤差範圍的折線圖
的plotrix封裝具有plotCI:
require(plotrix)
y<-runif(10)
err<-runif(10)
plotCI(1:10,y,err,2*err,lwd=2,col="red",scol="blue",
main="Add colors to the points and error bars")
lines(1:10, y)
(一種非常細微調整到例如碼是添加線連接的中點)
甲ggplot2
解決方案:
我將使用美國人口數據集R:
population <- data.frame(Year=seq(1790, 1970, length.out=length(uspop)),
Population=uspop,
Error=rnorm(length(uspop), 5))
library(ggplot2)
ggplot(population, aes(x=Year, y=Population,
ymin=Population-Error, ymax=Population+Error))+
geom_line(colour="red", size=1.2)+
geom_point(pch=2)+
geom_errorbar(width=0.9)