【问题标题】:sjPlot - change plot line colors to black/whitesjPlot - 将绘图线颜色更改为黑色/白色
【发布时间】:2018-10-04 08:59:33
【问题描述】:

我正在使用 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 谢谢!!

【问题讨论】:

    标签: r ggplot2 colors themes sjplot


    【解决方案1】:

    主题选项改变网格和轴标签等的外观,但改变几何图形(如点或线)。因此,您可以在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")
    

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

    【讨论】:

    • 感谢您的超级快速回答。
    • 它确实将我的线条分别设置为灰度或黑白。但是,在黑白中,它不会自动区分线型(我有两条不同的线,最初是蓝色和红色),例如,一条实线,一条虚线,正如您在小插图中指出的那样。我尝试将linetype = c(1,2)-argument 添加到plot_model(),但这并没有成功。有没有办法手动调整线型?
    • 我添加了一个工作示例。我不确定什么对你不起作用,也许你可以file an issue?如果你想改变线型
    • colors="bw" 参数是我将主题颜色转换为黑白所需的全部。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 2011-05-06
    相关资源
    最近更新 更多