簡體   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