我想按年计算平均CPUE并添加已计算的CI。
根据拖网调查数据的方法计算CI,因此我认为我不能使用R中可用的任何CI绘图功能。我真的很感激任何帮助。
我一直试图通过我在网上找到的示例来解决这个问题,但CI并未在我的数据点上绘制。我在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")
我的情节尝试是:
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)
答案 0 :(得分:2)
Andre的回答here帮助我找到了解决方案。
情节数据
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(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"))