简体   繁体   English

如何调整 effect_plot function 中的 y 轴范围

[英]How to adjust the y-axis range in effect_plot function

I'm trying to plot raw outcome values against variable insulin , with a regression line on top.我正在尝试针对变量insulin plot 原始结果值,顶部有一条回归线。 I followed the instruction here https://cran.r-project.org/web/packages/jtools/vignettes/effect_plot.html but I have a question about adjusting y-axis.我按照https://cran.r-project.org/web/packages/jtools/vignettes/effect_plot.html此处的说明进行操作,但我对调整 y 轴有疑问。

Do you know how may I customize my y-axis scales?你知道如何自定义我的 y 轴刻度吗? For example, how can I set y-axis scale ranged from -10 to 0, with -2 increment?例如,如何设置 y 轴刻度范围从 -10 到 0,增量为 -2? Sorry for this silly question, I'm new to R and most code I googled did not seem to work with the effect_plot() function.抱歉这个愚蠢的问题,我是 R 的新手,我搜索的大多数代码似乎不适用于effect_plot() function。 Below is my code:下面是我的代码:

pct_fat <- lm(pct_fat_change ~ DXA_age + female + race + hispanic + insulin, data = example)


effect_plot(example, pred = insulin, interval = TRUE, plot.points = TRUE, colors = "red")

Many thanks in advance!提前谢谢了!

Here's a toy example to change the y_axis limits.这是一个更改 y_axis 限制的玩具示例。

effect_plot returns a ggplot object, so assign it to a variable. effect_plot 返回一个 ggplot object,因此将其分配给一个变量。

library(ggplot2)
require(jtools)

data(mpg)

fit <- lm(cty ~ displ + year + cyl + class + fl, data = mpg[mpg$fl != "c",])

g <- effect_plot(fit, pred = displ, interval = TRUE, plot.points = TRUE, colors = "red")

After that, you can work on it as a ggplot object, here below 2 distinct way to achieve your result.之后,您可以将其作为 ggplot object 进行处理,下面有两种不同的方式来实现您的结果。 (Suppose you want to rescale the y_axis from 20 to 32) (假设您想将 y_axis 从 20 重新缩放到 32)

g +
  scale_y_continuous(limits=c(20, 32))

g+
  ylim(20, 32)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM