问题描述
我想使用 sjPlot::plot_model
生成一些边际效应图,这些图稍后会稍作修改。具体来说,我想用有序的分类预测器运行回归。然后我想在回归对象上运行 plot_model
以生成一个 ggplot2
对象,但为了便于可视化而删除了分类预测器的一些元素(例如,从回归中的 10 个类别到回归中的 5 个类别)情节)。
我知道我可以使用 ggeffects::ggpredict()
生成 plot_model
使用的基础数据,但希望有更简单的方法,例如将参数传递给 scale_x_discrete()
。
这是标准的 plot_model
输出。有没有一种直接的方法可以删除一个 x 轴元素,比如“6”,但仍然绘制“4”和“8”?
library(sjPlot)
mt <- mtcars
mt$cyl_fct <- as.factor(mt$cyl)
# automatic transmission vs number of cylinders
glm_out <- glm(am ~ cyl_fct,family = binomial,data = mt)
# plot model works fine but how to just show just 4 and 8 on x-axis?
plot_model(glm_out,type = "eff",terms = "cyl_fct") +
scale_y_continuous(labels = scales::percent_format(accuracy = 0.1))
# options like `breaks` and `limits` don't seem to do the trick
plot_model(glm_out,terms = "cyl_fct") +
scale_y_continuous(labels = scales::percent_format(accuracy = 0.1)) +
scale_x_discrete(breaks = c("4","8"),limits = c("4","8"))
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)