英文:
How to add CI whiskers and vertical lines to plot_model?
问题
我正在绘制一个具有两个分类变量的模型,每个变量都有两个类别。我试图实现类似以下的效果:
而实际上我得到了这样的结果:
这是我的代码:
install.packages("sjstats")
library(sjstats)
install.packages("sjPlot")
library(sjPlot)
plot_model(my_model, type = "pred", terms = c("Language", "Switching"),
axis.title = "Response Times (log)", legend.title = "Condition",
colors = "Set2", dot.size = 3, line.size = 1.5, ci = TRUE, ci.lvl = 0.95)
抱歉,我无法分享模型或其中的一个小的可复现部分,因此无法使用 dput
进行子集操作,也无法在这里分享整个数据集。
我的问题主要在于我用来显示图形的箱线图和置信区间的参数,但它们似乎由于某种原因不起作用。此外,有关如何获取垂直线的建议吗?vline
参数似乎也无效...
编辑:
在使用neilfws建议的下面代码编辑后,我得到了以下结果:
英文:
I'm plotting a model with two categorical variables, each with 2 categories. My attempt is to have something like the below:
Instead what I have is this:
Here is my code:
install.packages("sjstats")
library(sjstats)
install.packages("sjPlot")
library(sjPlot)
plot_model(my_model, type = "pred", terms = c("Language", "Switching"),
axis.title = "Response Times (log)", legend.title = "Condition",
colors = "Set2", dot.size = 3, line.size = 1.5, ci = TRUE, ci.lvl = 0.95)
Sorry for not being able to share the model or a small reproducible part of it, but I'm not able to subset from it using dput
and I'm not yet able to share the whole dataset on here.
My issue is more in the arguments that I'm using to show the whiskers of the plot the confidence intervals but they don't seem to work for some reason. Also, any suggestions on how to get the vertical line? vline
arguments don't work either...
EDIT:
After editing with the suggested code below by neilfws, this is what I get:
答案1
得分: 1
以下是您要翻译的内容:
"plot_model"的输出与给定的参数一样,符合预期。这种类型的模型不会绘制盒须图。
但是,"plot_model"的输出是一个ggplot对象,因此您可以通过添加geoms来修改它。
这是一个简单的示例。如果您想要更适合您的数据的代码,需要共享一些数据。
library(sjPlot)
library(ggplot2)
library(dplyr)
fit <- mtcars %>%
mutate(am = factor(am)) %>%
glm(vs ~ am, ., family = 'binomial')
plot_model(fit, type = "pred", terms = "am") +
geom_errorbar(
aes(ymin = conf.low, ymax = conf.high),
width = 0.25) +
geom_line()
结果:
英文:
The output from plot_model
is as expected with the given arguments. The function does not plot whiskers for this kind of model.
However, the output from plot_model
is a ggplot object, so you can modify it by adding geoms.
Here is a simple example. You'll need to share some data if you want code more suited to your data.
library(sjPlot)
library(ggplot2)
library(dplyr)
fit <- mtcars %>%
mutate(am = factor(am)) %>%
glm(vs ~ am, ., family = 'binomial')
plot_model(fit, type = "pred", terms = "am") +
geom_errorbar(
aes(ymin = conf.low, ymax = conf.high),
width = 0.25) +
geom_line()
Result:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论