繁体   English   中英

如何在R中的vis.gam绘图中更改绘图区域颜色?

[英]How to change plot region colour in a vis.gam plot in R?

我有这个数据集:

sample <- structure(list(A = c(1415.6, 1345.3, 1321.7, 1234.5, 1567.8, 
1476.6, 1610.1, 1422.6, 1209.1, 1249.3, 1377.5, 1525.7, 1683.7, 
1500.1, 1565.3, 1737.4, 1321, 1477.8, 1642, 1608.1, 1427.8, 1608.2, 
1404.4, 1688.3, 1795.4), B = c(98, 457, 756, 971, 1148, 4260, 
16307, 42614, 69787, 76301, 80491, 82267, 83975, 85310, 86322, 
94492, 98798, 102514, 126045.986, 160848.998, 183607.7625, 212747.9255, 
249117.2874, 306092.91, 339609.8663), C = c(1.2397, 1.5526, -0.1829, 
-0.3298, -0.1945, 2.8669, 1.3536, 0.781, 0.0324, -1.4283, -0.4413, 
-0.8583, -0.039, -0.2464, -0.277, 2.0885, -0.6405, -0.1474, 1.8457, 
0.3913, -0.4248, 0.2472, 0.2216, 0.4489, -0.5306)), .Names = c("A", 
"B", "C"), class = "data.frame", row.names = c(NA, -25L))

我想在vis.gam函数中更改绘图区域的颜色(反转灰色-绘图轮廓中的数字越高,绘图区域的颜色越深,反之亦然):

library(mgcv)
m0 <-gam(C ~ A + B, data = sample)

vis.gam(m0, plot.type="contour", color="gray")

我只想反转调色板。 如果不可能,请手动更改。 我已经尝试过这种方法(我只是偶然地选择了名字)

vis.gam(m0,plot.type="contour", col=c("#FFFFFF", "#F7F7F7", "666666"))
vis.gam(m0,plot.type="contour", col=("grey25", "grey26", "grey27"))

但这不起作用。

不幸的是vis.gam的定义不允许您想要的。 幸运的是,修改此函数以执行您想要的操作相当容易:

 # first get the definition of vis.gam
 newDef <- deparse(vis.gam)

 # change the line defining the direction of the grey gradient
 newDef[grep("gray\\(seq\\(",newDef)] <- "            pal <- gray(seq(0.9, 0.1, length = nCol))"

 # then define a new function with this new definition
 vis.gam2 <- eval(parse(text=newDef))

现在使用vis.gam2将完成您想要的操作:

vis.gam2(m0, plot.type="contour", color="gray")

暂无
暂无

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

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