【问题标题】:How to change plot region colour in a vis.gam plot in R?如何更改 R 中 vis.gam 图中的绘图区域颜色?
【发布时间】:2015-03-25 14:03:58
【问题描述】:

我有这个数据集:

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"))

但这不起作用。

【问题讨论】:

    标签: r gam


    【解决方案1】:

    不幸的是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")
    

    【讨论】:

    • 对不起,我错误地指定了问题。我想更改绘图区域的颜色,而不是绘图边距。我编辑了我的问题。
    • 知道了,我添加了答案。
    猜你喜欢
    • 1970-01-01
    • 2016-02-13
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    • 2016-03-29
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多