使用 plotCI 绘图时缩放轴刻度标签的问题

Problems scaling axis tick labels when plotting with plotCI

我正在使用 'gplots' 包中的绘图函数 plotCI 绘制点和置信区间,但我找不到正确的方法来操纵刻度标签大小。这是我的数据框 'bb':

DPUT(bb)
structure(list(Year = c(1970, 1971, 1972, 1973, 1974, 1975, 1976, 
1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 
1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018), F = c(28, 
31, 27, 34, 24, 16, 18, 33, 31, 25, 33, 34, 46, 45, 45, 40, 18, 
18, 25, 14, 21, 16, 21, 20, 21, 20, 18, 24, 26, 17, 24, 16, 18, 
15, 21, 35, 53, 64, 51, 52, 59, 52, 56, 52, 50, 51, 44, 20, 30
), M = c(24, 39, 53, 39, 41, 18, 17, 33, 45, 48, 48, 60, 47, 
34, 36, 35, 28, 27, 24, 32, 29, 30, 35, 35, 38, 40, 37, 34, 43, 
31, 34, 44, 45, 46, 51, 61, 112, 109, 116, 119, 89, 106, 103, 
82, 87, 81, 67, 44, 35), U = c(7, 4, 3, 8, 7, 42, 29, 6, 21, 
14, 18, 7, 13, 13, 12, 40, 12, 51, 24, 0, 0, 0, 14, 79, 60, 64, 
67, 81, 96, 98, 68, 97, 118, 206, 156, 136, 1, 0, 0, 1, 0, 1, 
5, 1, 1, 4, 1, 71, 82), Tot = c(59, 74, 83, 81, 72, 76, 64, 72, 
97, 87, 99, 101, 106, 92, 93, 115, 58, 96, 73, 46, 50, 46, 70, 
134, 119, 124, 122, 139, 165, 146, 126, 157, 181, 267, 228, 232, 
166, 173, 167, 172, 148, 159, 164, 135, 138, 136, 112, 135, 147
), ratio = c(0.857142857142857, 1.25806451612903, 1.96296296296296, 
1.14705882352941, 1.70833333333333, 1.125, 0.944444444444444, 
1, 1.45161290322581, 1.92, 1.45454545454545, 1.76470588235294, 
1.02173913043478, 0.755555555555556, 0.8, 0.875, 1.55555555555556, 
1.5, 0.96, 2.28571428571429, 1.38095238095238, 1.875, 1.66666666666667, 
1.75, 1.80952380952381, 2, 2.05555555555556, 1.41666666666667, 
1.65384615384615, 1.82352941176471, 1.41666666666667, 2.75, 2.5, 
3.06666666666667, 2.42857142857143, 1.74285714285714, 2.11320754716981, 
1.703125, 2.27450980392157, 2.28846153846154, 1.50847457627119, 
2.03846153846154, 1.83928571428571, 1.57692307692308, 1.74, 1.58823529411765, 
1.52272727272727, 2.2, 1.16666666666667), popsize = c(NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, 2074, 2074, 2074, 2074, 2074, 
2074, 2074, 1546, 1546, 1546, 1546, 1546, 1546, 1546, 1546, 1546, 
2826, 2826, 2826, 2826, 2826, 2826)), row.names = c(NA, -49L), class = c("tbl_df", 
"tbl", "data.frame"))

这是我的脚本:

library(mgcv)

m.bb <- gam(Tot~s(Year,k=5),family=poisson,data=bb)
YearP=seq(1970,2018,by=1)
mbb.pred=predict(m.bb,newdata=data.frame(Year=YearP),type="response",se.fit=T)

library(gplots)
par(mfrow=c(4,4))
par(mar=c(2.5, 6, 2.5, 0.2) + 0.2)

plotCI(x=YearP, y=mbb.pred$fit,uiw=2*mbb.pred$se.fit, type="l",sfrac=0.003,
   ylim=c(50,300),xlim=c(1970,2020),
   col="red",gap=0,lwd=1.6,cex=1.2,las=1, 
   xlab="", ylab="Y axis label")
axis(side=1,size=3)
points(bb$Year,bb$Tot,pch=19,cex=0.9)
mtext('TITLE', side=3, line=0.8, at=1969,adj=0,cex=1.1)

这是输出图:

我正在尝试增加刻度标签的大小,但找不到可行的方法。任何帮助表示赞赏。

您可以使用 cex.axis= 调整 x 轴刻度标签大小。当心这段代码可能比它需要的更冗长...

关键是启动一个空的绘图区域,在plotCI()中使用add=TRUEcol.axis = NA,并手动指定绘图属性。

library(mgcv)

m.bb <- gam(Tot~s(Year,k=5),family=poisson,data=bb)
YearP=seq(1970,2018,by=1)
mbb.pred=predict(m.bb,newdata=data.frame(Year=YearP),type="response",se.fit=T)

library(gplots)
#par(mfrow=c(4,4))
#par(mar=c(2.5, 6, 2.5, 0.2) + 0.2)

plot(x=NA, y=NA, ylim=c(50,300), xlim=c(1970,2020), col.axis = NA, ylab = "", xlab = "")
plotCI(x=YearP, y=mbb.pred$fit, uiw=2*mbb.pred$se.fit, type="l",sfrac=0.003,
       col="red",gap=0,lwd=1.6,cex=1.2,las=1, 
       xlab="", ylab="Y axis label",
       add = TRUE, col.axis = NA)
axis(side=1, cex.axis = 2)
axis(side=2, col = "black")
title(ylab = "Y axis label")
points(bb$Year,bb$Tot,pch=19,cex=0.9)
mtext('TITLE', side=3, line=0.8, at=1969,adj=0,cex=1.1)