r - 在包 sjPlot::plot_model() 中定义 y 轴范围和中断
问题描述
我正在使用 sjplot 包和 R 中的函数 plot_model (max.m3) 绘制 GlmmTMB 模型的结果。这是代码:
p=sjPlot::plot_model(max.m3, type="pred", grid = F)
这些是绘制的六个图形。但是,我想定义 y 轴范围(范围从 0 到 10)并显示中断(0、5、10 = 以便刻度线出现在 0、5 和 10 处)。
不幸的是,我没有找到解决方案。
解决方案
如果为所有模型项绘制边际效应,则plot_model()
返回ggplot 对象列表。然后,您可以简单地使用 ggplot-commands 修改列表中的每个图。
m <- lm(mpg ~ hp + gear + cyl + drat, data = mtcars)
p <- sjPlot::plot_model(m, type = "pred", grid = FALSE)
p[[1]] + scale_y_continuous(limits = c(15, 30), breaks = c(15, 25, 30))
p[[2]] + scale_y_continuous(limits = c(5, 40), breaks = c(15, 25, 40))
...
如果您想对所有绘图应用相同的 y 限制和中断,您可以遍历列表,例如:
library(ggplot2)
m <- lm(mpg ~ hp + gear + cyl + drat, data = mtcars)
p <- sjPlot::plot_model(m, type = "pred", grid = FALSE)
lapply(p, function(i) i + scale_y_continuous(limits = c(15, 30), breaks = c(15, 25, 30)))
推荐阅读
- r - 平均数据以生成带有 geom_contour_filled 的图
- javascript - 构建 Vuejs Tailwindcss 背景图片
- python - 如果某人具有特定的权限/角色,则使他们免于亵渎过滤器 discord.py
- python - 在熊猫中填充nan时添加偏移量
- azure - 使用数据工厂附加到 azure 数据湖中的文件
- graphql - Strapi Graphql 查询日期和关系
- dynamic - 要嵌入的动态帮助cmd
- c - 从字符串初始化 uInt128 值
- bash - 如何按字符串集中两个不同分隔符之间包含的数值进行bash排序
- python - 错误 take() 不接受布尔索引器