[英]How to increase the border lines width in plot.gam with multiple plots
亲爱的 StackOverflow 用户,
我需要增加我的多个 GAM 图的边界线宽度。 我尝试使用box(lwd=3)
,但它只适用于最后一个数字。 所以我的问题是如何增加每个图形的边框线宽。
这是我的代码
Gam_AF_species <- gam(Species.AF ~ s(SST) + s(SBT, k=3) + s(Salinity) +
s(Primary.productivity), data = Data)
par(mfrow = c(1,4))
plot.gam(Gam_AF_species, ylab="", xlab="", cex.lab = 1.5, cex.axis= 1.5,
cex.main = 3, lwd = 3, lwd.tick = 3)
box(lwd=3)
我也试过不使用par(mfrow=c(1,4)
,然后数字会一一出来,我确实成功增加了每个数字的边框线宽。但是,我有超过30个数字需要绘制,所以这种方式效率不高,希望大家给点建议,谢谢。
您需要分别绘制每个面板; 您对box(lwd = 3)
调用仅在生成最终图之后才出现,因此它只能影响最终图。
要单独绘制各个面板,我将使用plot.gam()
的select
参数来选择我想要绘制的平滑。
这最容易通过创建一个快速包装函数来完成,该函数结合了您对plot.gam()
的调用和对box()
的调用。
包装函数可能如下所示
my_plot_fun <- function(smooth) {
plot(m, select = smooth,
ylab="", xlab="", cex.lab = 1.5, cex.axis= 1.5,
cex.main = 3, lwd = 3)
box(lwd = 3)
}
其中所有选项都是硬编码的,甚至是要绘制的模型,并且我们作为参数传入的唯一想法是通过我们在plot.gam()
调用中传递给select
的参数来绘制smooth
。
然后我会使用一个简单的for
循环来调用包装函数来依次绘制每个平滑。
以下是如何执行此操作的完整示例:
library('mgcv')
# simulate some data
set.seed(1)
df <- gamSim(1)
# fit the GAM
m <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = df, method = "REML")
# wrapper function for the plot you want
my_plot_fun <- function(smooth) {
plot(m, select = smooth,
ylab="", xlab="", cex.lab = 1.5, cex.axis= 1.5,
cex.main = 3, lwd = 3)
box(lwd = 3)
}
# set up the plot to have 1 row and 4 columns
layout(matrix(1:4, ncol = 4))
# loop over the indices 1, 2, 3, 4 to plot each smooth in turn
for (i in seq_len(4)) {
my_plot_fun(i)
}
# reset the device
layout(1)
您可以用par(mfrow)
调用替换最后一位,如
# set up the plot to have 1 row and 4 columns
op <- par(mfrow = c(1,4))
# loop over the indices 1, 2, 3, 4 to plot each smooth in turn
for (i in seq_len(4)) {
my_plot_fun(i)
}
# reset the device
par(op)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.