如何使用 Sjplot 更改 facet_grid 和点估计的形状?
How to change the facet_grid and the shape of point estimates with Sjplot?
我需要使用 plot_model 自定义绘图,这是一个用于绘制广义线性混合效应模型的函数。
我有一个显示系数的森林图和一个显示概率的线图。
在下面的森林图中,我有两个级别的年龄因素(年轻人,老年人)。我想要实现的是改变两组的点估计形状,例如,为年轻人显示一个圆圈,为老年人显示一个菱形。在下图中,我希望 "Age:New"、"Age:Lure"、"Age:Old" 具有不同的形状。但是,我没有找到任何额外的论据允许我这样做。有什么想法吗?
森林图
同样,在下面的线图中,我想将 facet_grid 标签从 0 和 1 更改为 "Young adults" 和 "Older adults"。这可以通过 ggplot2 实现,但是当我使用 sjplot 时,我想知道是否有一种方法可以在其中实现它。
线图
我已经绘制了我的模型,但是我想获得一些额外的灵活性。
这是森林图的代码:
plot_model(model1_original_conf, type = "est", transform = NULL, terms = c("ZcConfusabilitySimWeightedSim",
"Age1:ZcConfusabilitySimWeightedSim",
"Conditionlure:ZcConfusabilitySimWeightedSim",
"Conditionold:ZcConfusabilitySimWeightedSim",
"Age1:Conditionlure:ZcConfusabilitySimWeightedSim",
"Age1:Conditionold:ZcConfusabilitySimWeightedSim"),
colors = c("seagreen3", "deepskyblue2", "orchid"),
show.values = TRUE,
value.offset = .4,
value.size = 6,
dot.size = 6,
line.size = 2.5,
vline.color = "red",
width = 0.5,
axis.labels = c("Age:New", "New", "Age:Lure", "Lure", "Age:Old", "Old"),
title = "Semantic Confusability",
order.terms = c(4,6,3,5,1,2),
group.terms = c(1,1,2,3,2,3))
这是线图的代码:
plot_model(model1_original_conf, type = "pred",
terms = c("ZcConfusabilitySimWeightedSim", "Condition", "Age"),
colors = c("seagreen3", "deepskyblue2", "orchid"),
title = "Raw probabilities",
axis.title = c("Semantic Confusability", "p (judge item is OLD)"),
line.size = 2.0)
我希望找到 1) 森林图中点估计的不同形状(例如,圆形和三角形或菱形)和 2)线图中 0 和 1 的适当标签("young adults" 和"older adults").
However, I do not find any extra argument that allows me to do so. Any Idea?
您需要 ggplot2::aes()
来更新映射,然后您可以将 scale_shape_manual()
添加到从 plot_model()
返回的绘图中。
示例:
library(sjPlot)
library(ggplot2)
m <- lm(Sepal.Length ~ Petal.Width + Petal.Length + Species, data = iris)
plot_model(m, group.terms = c(1, 1, 2, 2)) +
aes(shape = group) +
scale_shape_manual(values = c(1, 4))
由 reprex package (v0.2.1)
于 2019-05-06 创建
I would like to change the facet_grid labels from 0 and 1 to "Young adults" and "Older adults".
当你有一个具有所需因子水平的因子时,这应该有效:
library(sjPlot)
library(ggplot2)
library(sjmisc)
set.seed(123)
iris$binary <- sample(c(0, 1), nrow(iris), replace = T)
iris$Sepal.Length_d <- sjmisc::dicho(iris$Sepal.Length)
m2 <- glm(Sepal.Length_d ~ Petal.Width + Petal.Length * Species * binary, data = iris, family = binomial())
plot_model(m2, type = "pred", terms = c("Petal.Length", "Species", "binary"), ci.lvl = NA)
iris$binary <- sjmisc::rec(iris$binary, rec = "0=young adults;1=older adults", as.num = FALSE)
m3 <- glm(Sepal.Length_d ~ Petal.Width + Petal.Length * Species * binary, data = iris, family = binomial())
plot_model(m3, type = "pred", terms = c("Petal.Length", "Species", "binary"), ci.lvl = NA)
由 reprex package (v0.2.1)
于 2019-05-06 创建
我需要使用 plot_model 自定义绘图,这是一个用于绘制广义线性混合效应模型的函数。 我有一个显示系数的森林图和一个显示概率的线图。
在下面的森林图中,我有两个级别的年龄因素(年轻人,老年人)。我想要实现的是改变两组的点估计形状,例如,为年轻人显示一个圆圈,为老年人显示一个菱形。在下图中,我希望 "Age:New"、"Age:Lure"、"Age:Old" 具有不同的形状。但是,我没有找到任何额外的论据允许我这样做。有什么想法吗?
森林图
同样,在下面的线图中,我想将 facet_grid 标签从 0 和 1 更改为 "Young adults" 和 "Older adults"。这可以通过 ggplot2 实现,但是当我使用 sjplot 时,我想知道是否有一种方法可以在其中实现它。
线图
我已经绘制了我的模型,但是我想获得一些额外的灵活性。
这是森林图的代码:
plot_model(model1_original_conf, type = "est", transform = NULL, terms = c("ZcConfusabilitySimWeightedSim",
"Age1:ZcConfusabilitySimWeightedSim",
"Conditionlure:ZcConfusabilitySimWeightedSim",
"Conditionold:ZcConfusabilitySimWeightedSim",
"Age1:Conditionlure:ZcConfusabilitySimWeightedSim",
"Age1:Conditionold:ZcConfusabilitySimWeightedSim"),
colors = c("seagreen3", "deepskyblue2", "orchid"),
show.values = TRUE,
value.offset = .4,
value.size = 6,
dot.size = 6,
line.size = 2.5,
vline.color = "red",
width = 0.5,
axis.labels = c("Age:New", "New", "Age:Lure", "Lure", "Age:Old", "Old"),
title = "Semantic Confusability",
order.terms = c(4,6,3,5,1,2),
group.terms = c(1,1,2,3,2,3))
这是线图的代码:
plot_model(model1_original_conf, type = "pred",
terms = c("ZcConfusabilitySimWeightedSim", "Condition", "Age"),
colors = c("seagreen3", "deepskyblue2", "orchid"),
title = "Raw probabilities",
axis.title = c("Semantic Confusability", "p (judge item is OLD)"),
line.size = 2.0)
我希望找到 1) 森林图中点估计的不同形状(例如,圆形和三角形或菱形)和 2)线图中 0 和 1 的适当标签("young adults" 和"older adults").
However, I do not find any extra argument that allows me to do so. Any Idea?
您需要 ggplot2::aes()
来更新映射,然后您可以将 scale_shape_manual()
添加到从 plot_model()
返回的绘图中。
示例:
library(sjPlot)
library(ggplot2)
m <- lm(Sepal.Length ~ Petal.Width + Petal.Length + Species, data = iris)
plot_model(m, group.terms = c(1, 1, 2, 2)) +
aes(shape = group) +
scale_shape_manual(values = c(1, 4))
由 reprex package (v0.2.1)
于 2019-05-06 创建I would like to change the facet_grid labels from 0 and 1 to "Young adults" and "Older adults".
当你有一个具有所需因子水平的因子时,这应该有效:
library(sjPlot)
library(ggplot2)
library(sjmisc)
set.seed(123)
iris$binary <- sample(c(0, 1), nrow(iris), replace = T)
iris$Sepal.Length_d <- sjmisc::dicho(iris$Sepal.Length)
m2 <- glm(Sepal.Length_d ~ Petal.Width + Petal.Length * Species * binary, data = iris, family = binomial())
plot_model(m2, type = "pred", terms = c("Petal.Length", "Species", "binary"), ci.lvl = NA)
iris$binary <- sjmisc::rec(iris$binary, rec = "0=young adults;1=older adults", as.num = FALSE)
m3 <- glm(Sepal.Length_d ~ Petal.Width + Petal.Length * Species * binary, data = iris, family = binomial())
plot_model(m3, type = "pred", terms = c("Petal.Length", "Species", "binary"), ci.lvl = NA)
由 reprex package (v0.2.1)
于 2019-05-06 创建