gpt4 book ai didi

r - sjPlot - 将绘图线颜色更改为黑色/白色

转载 作者:行者123 更新时间:2023-12-03 18:23:57 29 4
gpt4 key购买 nike

我正在使用 sjPlot 的 plot_model() 绘制回归模型。我想将我的线条颜色从 sjPlot 主题(红色和蓝色线条)更改为黑白或灰度。但是,当我使用 set_theme(theme_bw()) 时,绘图外观不会改变(theme_bw 来自 ggplot2,根据我在键入函数时看到的下拉菜单)。

然而,当我选择一个可用的 sjPlot 主题(theme_538theme_blanktheme_sjplottheme_sjplot2 ),它们都将线条渲染为红色和蓝色,但改变了绘图背景,所以我认为我的功能是正确的。

如何使用 bw 或 gs 主题或手动将线条颜色设置为黑白色?

library(ggplot2)
library(sjPlot)
library(sjmisc)
#set_theme(theme_bw()) # this does not change the plot appearance
set_theme(theme_538()) # this does change the plot background appearance

M <- glm(DV ~ IV1 + IV2 + IV3 + IV1*IV2*IV3, data = data5, family = quasibinomial("logit"))
p <- plot_model(M, type = "pred", terms = c("IV1", "IV2", "IV3 [-1,0,1]"), theme = theme_get())
p

ps:根据我在网上找的sjPlot资源,sjPlot主题应该比我看到的多。这很奇怪。此外,我读到 set_theme() 函数应该适用于 ggplot2 主题,但这里似乎并非如此。知道错误在哪里吗?也许我正在监督一些非常简单的事情?

编辑:我使用的是 R 版本 3.5.0 和 Rstudio 版本 1.1.383谢谢!!

最佳答案

主题选项会改变网格和轴标签等的外观,但不会几何图形(如点或线)。因此,您可以在 plot_model() 中使用 colors 参数。有一些例子in this vignettes .我猜你的解决方案是:

plot_model(M, type = "pred", terms = c("IV1", "IV2", "IV3 [-1,0,1]"), colors = "gs")

plot_model(M, type = "pred", terms = c("IV1", "IV2", "IV3 [-1,0,1]"), colors = "bw")


library(sjPlot)
data(efc)
fit <- lm(barthtot ~ c12hour + neg_c_7 * c161sex * c172code, data = efc)
plot_model(fit, type = "pred", terms = c("neg_c_7", "c172code", "c161sex"), colors = "bw")

enter image description here

plot_model(fit, type = "pred", terms = c("neg_c_7", "c172code", "c161sex"), colors = "gs")

enter image description here

关于r - sjPlot - 将绘图线颜色更改为黑色/白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52642858/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com