简体   繁体   English

用R绘制置信区间数据

[英]Plotting confidence intervals data with R

I would like to plot mean CPUE by year and add in CIs that are already calculated. 我想按年绘制平均CPUE并添加已经计算的CI。

The CIs are calculated following an approach for trawl survey data so I do not think I can use any of the CI plot functions available in R. I would really appreciate any help. 配置项是根据拖网调查数据的一种方法计算的,因此我认为我无法使用R中可用的任何配置项绘图功能。我将非常感谢您的帮助。

I have been trying to figure this out following examples I found online, but the CIs are not being plotted on my data points. 我一直在尝试根据在网上找到的示例来弄清楚这一点,但是CI并没有绘制在我的数据点上。 I have R version 3.1.0 on windows 8. This is my code. 我在Windows 8上有R版本3.1.0。这是我的代码。

dput(fall)

structure(list(Year = structure(1:7, .Label = c("2007", "2008", 
"2009", "2010", "2011", "2012", "2013", "2014"), class = "factor"), 
    Season = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Fall", 
    "Spring"), class = "factor"), CPUE = c(2.67597320766895, 
    1.13720423803133, 3.33880765324431, 0.806172684858967, 1.4489759307485, 
    10.5492990950043, 4.52479039663784), Variance = c(6.80824504958873, 
    0.320707030421567, 11.5769406857122, 1.05791053306542, 0.187046436602381, 
    15.8421823978692, 2.68384838783695), SD = c(2.60926139924476, 
    0.566310012644635, 3.40249036526369, 1.0285477786984, 0.432488654882855, 
    3.98022391303168, 1.63824552123207), Number = c(75, 91, 87, 
    85, 115, 157, 208), CV = c(0.975070076100538, 0.497984437364567, 
    1.01907348929115, 1.27584052153583, 0.298478839920718, 0.377297475139038, 
    0.362059980159386), lower = c(2.07563668109912, 1.01926446969017, 
    2.61363856286983, 0.584320068914576, 1.36908295705723, 9.92183627713643, 
    4.30084507885747), upper = c(3.27630973423878, 1.2551440063725, 
    4.06397674361879, 1.02802530080336, 1.52886890443977, 11.1767619128722, 
    4.7487357144182)), .Names = c("Year", "Season", "CPUE", "Variance", 
"SD", "Number", "CV", "lower", "upper"), row.names = c(NA, 7L
), class = "data.frame")

My plot attempt was: 我的阴谋尝试是:

plot(fall$CPUE, type='n', xlab="Year", ylab='Mean CPUE', axes=F)
axis(1, at=1:8, labels=levels(fall$Year))
axis(2)
box()
lines(fall$Year, fall$CPUE, col=1)
points(fall$Year, fall$CPUE, col=1, pch=16)
arrows(y0 = fall$lower, y1 = fall$upper, x0 = fall$CPUE, x1 = fall$CPUE, 
length=0.1, code = 3, col = 4, angle = 90) 

Andre's answer here helped me to find a solution. 安德烈在这里的回答帮助我找到了解决方案。

Data for plot 绘图数据

structure(list(CPUE = c(2.67597320766895, 1.13720423803133, 3.33880765324431, 0.806172684858967, 1.4489759307485, 10.5492990950043, 4.52479039663784 ), lower = c(2.25499288520513, 1.04583532734779, 2.80755247046762, 0.640225963050555, 1.37919786502951, 9.90712658332295, 4.26047455308042 ), upper = c(3.09695353013276, 1.22857314871488, 3.870062836021, 0.972119406667378, 1.51875399646749, 11.1914716066857, 4.78910624019525 )), .Names = c("CPUE", "lower", "upper"), class = "data.frame", row.names = c(NA, 7L))

Plot 情节

plot(fall$CPUE, type='l', xlab="Year", ylab='Mean CPUE', axes=F,ylim=c(0,12)) 
axis(1, at=1:8, labels=levels(fall$Year)) 
axis(2) 
box() 

require(plotrix)

plotCI(fall$CPUE,y=NULL,uiw = fall$upper-fall$CPUE,ui=NULL,li=NULL,err="y", sfrac=0.01,gap=0,slty=par("lty"),add=T,scol="black",pch=18,pt.bg=par("bg"))

在此处输入图片说明

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

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