简体   繁体   中英

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

I have this dataset:

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

and I want to change the plot region colour in vis.gam function (invert the grey colour - the higher the number in the plot contours the darker the colour of the plot region and vice versa):

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

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

I would like to just invert the colour palette. If not possible, change it manually. I've tried somethoing like this (I choosed names only by chance)

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

but that is not working.

Unfortunately the definition of vis.gam doesn't allow what you want. Fortunately, it is fairly easy to modify this function to do what you want:

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

Now using vis.gam2 will do what you want:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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