在 R 中获取 sjPlot 以显示和排序估计值
我正在尝试在 sjPlot 中制作一个交互图,显示在我的预测变量的两种条件下我的结果的百分比概率。一切都很完美,除了 show.values = T 和 sort.est = T 参数,它们似乎没有做任何事情。有办法让它发挥作用吗?或者,如果没有,我如何提取 sjPlot 用于创建该图的数据帧?寻找某种方法来标记或制表显示的概率值。谢谢你!
以下是一些示例数据以及迄今为止我所拥有的数据:
set.seed(100)
dat <- data.frame(Species = rep(letters[1:10], each = 5),
threat_cat = rep(c("recreation", "climate", "pollution", "fire", "invasive_spp"), 10),
impact.pres = sample(0:1, size = 50, replace = T),
threat.pres = sample(0:1, size = 50, replace = T))
mod <- glm(impact.pres ~ 0 + threat_cat/threat.pres,
data = dat, family = "binomial")
library(sjPlot)
library(ggpubr)
plot_model(mod, type = "int",
title = "",
axis.title = c("Threat category", "Predicted probabilities of threat being observed"),
legend.title = "Threat predicted",
colors = c("#f2bf10",
"#4445ad"),
line.size = 2,
dot.size = 4,
sort.est = T,
show.values = T)+
coord_flip()+
theme_pubr(legend = "right", base_size = 30)
I am trying to make an interaction plot in sjPlot showing percent probabiliites of my outcome under two conditions of my predictive variable. Everything works perfectly, except the show.values = T and sort.est = T arguments, which don't seem to do anything. Is there a way to get this to work? Or, if not, how can I extract the dataframe sjPlot is using to create this figure? Looking for some way to either label or tabulate the displayed probability values. Thank you!
Here is some example data and what I have so far:
set.seed(100)
dat <- data.frame(Species = rep(letters[1:10], each = 5),
threat_cat = rep(c("recreation", "climate", "pollution", "fire", "invasive_spp"), 10),
impact.pres = sample(0:1, size = 50, replace = T),
threat.pres = sample(0:1, size = 50, replace = T))
mod <- glm(impact.pres ~ 0 + threat_cat/threat.pres,
data = dat, family = "binomial")
library(sjPlot)
library(ggpubr)
plot_model(mod, type = "int",
title = "",
axis.title = c("Threat category", "Predicted probabilities of threat being observed"),
legend.title = "Threat predicted",
colors = c("#f2bf10",
"#4445ad"),
line.size = 2,
dot.size = 4,
sort.est = T,
show.values = T)+
coord_flip()+
theme_pubr(legend = "right", base_size = 30)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
sjPlot
生成一个 ggplot 对象,因此您可以检查美学映射和基础数据。经过一番挖掘后,您会发现文本标签的 x、y 位置的默认映射已经是正确的,因此您需要做的就是向绘图添加一个geom_text
,并且只需要将标签指定为美学映射。您可以从存储在 ggplot 对象中的名为predicted
的列中获取标签。结果是,如果您将以下图层添加到绘图中:
您将得到
按顺序获取标签比较棘手。你必须摆弄情节的内部组件才能做到这一点。假设我们将上面的图存储为
p
,那么我们可以通过执行以下操作按预测百分比进行排序:sjPlot
produces a ggplot object, so you can examine the aesthetic mappings and underlying data. After a bit of digging around you will find the default mapping is already correct for the x, y placements of text labels, so all you need to do is add ageom_text
to the plot, and only need to specify the labels as an aesthetic mapping. You can get the labels from a column calledpredicted
stored in the ggplot object.The upshot is that if you add the following layer to your plot:
You get
Getting the labels in order is trickier. You have to fiddle with the internal components of the plot to do this. Suppose we store the above plot as
p
, then we can sort by the predicted percentages by doing: