简体   繁体   English

有没有办法为 R 更改 pdp package 中的 header 颜色?

[英]Is there a way to change the header color in the pdp package for R?

Is it possible to change the header colour of plots in the pdp package for R?是否可以为 R 更改 pdp package 中绘图的 header 颜色? I would like the colour to be lightgrey.我希望颜色是浅灰色的。 You can remove the colour of the pdp plot individually, but if I want to arrange them in a grid the colour returns back to default.您可以单独删除 pdp plot 的颜色,但如果我想将它们排列在网格中,颜色将恢复为默认值。 For an example see below.有关示例,请参见下文。 Thanks in advance.提前致谢。

library(pdp)
library(grid)
library(gridExtra)

df <- data.frame(v1=rnorm(100), 
           v2=as.factor(sample(c("A","B","C"), 100, T)),
           v3=rlnorm(100))

mod    <- glm(v1~v2+v3, data=df)
modpdp <- pdp::partial(mod, grid.resolution = 10, pred.var = c("v2", "v3"))
p1     <- pdp::plotPartial(modpdp, trellis.par.set(strip.background=list(col="lightgrey")))
p2     <- pdp::plotPartial(modpdp, trellis.par.set(strip.background=list(col="lightgrey")))

grid.arrange(arrangeGrob(p1), arrangeGrob(p2))

It's a bit of a strange system.这是一个有点奇怪的系统。 You need to pass a strip = argument which itself takes the output of a lattice::strip.custom call.您需要传递一个strip =参数,该参数本身采用lattice::strip.custom调用的 output 。 It is inside the call to strip.custom where you set the colour using bg =它在对strip.custom的调用中,您可以在其中使用bg =设置颜色

library(pdp)
library(grid)
library(gridExtra)
library(lattice)

df <- data.frame(v1 = rnorm(100),
                 v2 = as.factor(sample(c("A", "B", "C"), 100, T)),
                 v3 = rlnorm(100))


mod    <- glm(v1 ~ v2 + v3, data = df)
modpdp <- partial(mod, grid.resolution = 10, pred.var = c("v2", "v3"))
p1     <- plotPartial(modpdp, strip = strip.custom(bg = "lightgrey"))
p2     <- plotPartial(modpdp, strip = strip.custom(bg = "lightgrey"))

grid.arrange(arrangeGrob(p1), arrangeGrob(p2))

Created on 2020-05-25 by the reprex package (v0.3.0)代表 package (v0.3.0) 于 2020 年 5 月 25 日创建

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

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