plot_model()函数(sjPlot包)中,将 colored颜色 设置为黑白colors="bw"不允许用户修改legend.title中图例标题中的字符串.在不修改数据本身的情况下,是否有解决方法?

EDIT

colors="bw"为例

plot_model(mod4, type="int",
           colors="bw",
           mdrt.values="minmax", 
           title = "",
           axis.title = c("Variable 1", "Response"),
           legend.title="Distance (Meters)"
           ) 

enter image description here

colors="Set1"

plot_model(mod4, type="int",
           colors="Set1",
           mdrt.values="minmax", 
           title = "",
           axis.title = c("Variable 1", "Response"),
           legend.title="Distance (Meters)"
           ) 

enter image description here

推荐答案

SjPlot的‘内部’是基于ggplot2的,因此您可以使用ggplot2命令来定制您的绘图.

示例绘图(从https://strengejacke.github.io/sjPlot/articles/plot_marginal_effects.html开始):

library(sjPlot)
library(ggplot2)
data(efc)
theme_set(theme_sjplot())

fit <- lm(barthtot ~ c12hour + neg_c_7 + c161sex + c172code, data = efc)

plot_model(fit, type = "pred", terms = c("c12hour", "c172code"))

使用colors = "bw":

plot_model(fit, type = "pred", terms = c("c12hour", "c172code"), colors = "bw")

更改图例标题:

plot_model(fit, type = "pred", terms = c("c12hour", "c172code"), colors = "bw") +
  scale_linetype_manual(name = "New Title",
                        values = c(1,2,3))

更改标题的 colored颜色 和大小:

plot_model(fit, type = "pred", terms = c("c12hour", "c172code"), colors = "bw") +
  scale_linetype_manual(name = "New Title",
                        values = c(1,2,3)) +
  theme(legend.title = element_text(colour = "red"))

创建于2023-10-19年第reprex v2.0.2


编辑

此外,在我的示例中,似乎更改legend.title确实有效:

library(sjPlot)
library(ggplot2)
data(efc)
theme_set(theme_sjplot())

fit <- lm(barthtot ~ c12hour + neg_c_7 + c161sex + c172code, data = efc)

plot_model(fit, type = "pred", terms = c("c12hour", "c172code"))


plot_model(fit, type = "pred", terms = c("c12hour", "c172code"), colors = "bw")


plot_model(fit, type = "pred", terms = c("c12hour", "c172code"),
           colors = "bw", legend.title = "new title")

创建于2023-10-19年第reprex v2.0.2

你能提供一个最小的可重现的例子来说明你的问题吗?您运行的是最新版本的R/sjPlot吗?

R相关问答推荐

for循环和if else在R中

try 在Powershell中运行R(编程语言)会重复最后一个命令

如何在球体上绘制轮廓线?

使用na.locf在长格式数据集中输入具有多个时间点的数据集

是否有任何解决方案可以优化VSCode中RScript的图形绘制?

给定R中另一行中的值,如何插补缺失值

按块将载体转换为矩阵-reshape

通过绘图 Select 线串几何体并为其着色

多个ggpredicate对象的平均值

保存包含循环和ifelse的函数的输出

方法::slotName如何处理非类、非字符的参数?

用两种 colored颜色 填充方框图

您是否可以使用facet_rap设置一个较低的限制来对ggmap上的比例中断进行zoom ?

`夹心::vcovCL`不等于`AER::tobit`标准错误

为什么在BASE R中绘制线条时会看到线上的点?

派生程序包| ;无法检索';return()';的正文

如何删除设置大小的曲线图并添加条形图顶部数字的百分比

根据r中每行中的日期序列,使用列名序列创建新列

如何使用循环从R中的聚合函数创建列,而不会在名称中给出&q;$&q;?

使用LAG和dplyr执行计算,以便按行和按组迭代