简体   繁体   English

如何在R中创建带有误差幅度的折线图

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

I am looking for a way to plot data on population proportion over time, with showing margins or error, similar to this example: http://goo.gl/dbrbu . 我正在寻找一种方法来绘制随时间变化的人口比例数据,并显示边距或误差,类似于以下示例: http : //goo.gl/dbrbu But could not find any instructions on that. 但是找不到任何说明。 Thanks! 谢谢!

在此处输入图片说明

A ggplot2 solution: ggplot2解决方案:

I'm going to use the US population dataset in R: 我将在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)

在此处输入图片说明

The plotrix package has plotCI: 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)

在此处输入图片说明

(A very minor tweak to the example code is to add lines connecting the midpoints.) (对示例代码的一个非常小的调整是添加连接中点的线。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM