簡體   English   中英

如何在R中創建帶有誤差幅度的折線圖

[英]How to create line chart with Margins of Error in R

我正在尋找一種方法來繪制隨時間變化的人口比例數據,並顯示邊距或誤差,類似於以下示例: http : //goo.gl/dbrbu 但是找不到任何說明。 謝謝!

在此處輸入圖片說明

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)

在此處輸入圖片說明

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)

在此處輸入圖片說明

(對示例代碼的一個非常小的調整是添加連接中點的線。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM