[英]Editing the y axis on a sjplot in R (plot_model)
I am having trouble with my y axis on this sjplot I have created.我在创建的这个 sjplot 上的 y 轴有问题。 I am not sure why the values are arranged like that (see image) and was wondering if anyone could help me eg set my y axis to start at 0.
我不确定为什么这些值是这样排列的(见图),并且想知道是否有人可以帮助我,例如将我的 y 轴设置为从 0 开始。
library(jtools)
library(carData)
library(effects)
library(sjPlot)
mod <- glmer(Golden.Trevally ~ Maturity.Status + Behavioural.Activity + (1 | ID.Number), family = "binomial", data = mydf2)
summary(mod)
plot_model(mod, "pred", title="")
By far the hardest part of answering this question was recreating your data to make it reproducible.到目前为止,回答这个问题最难的部分是重新创建数据以使其可重现。 However, the following is pretty close:
但是,以下内容非常接近:
library(jtools)
library(carData)
library(effects)
library(sjPlot)
library(lme4)
set.seed(69)
Behavioural.Activity <- factor(sample(c("Cleaning", "Courtship",
"Cruising", "Feeding"),
size = 10000,
replace = TRUE))
Maturity.Status <- factor(sample(LETTERS[1:3], 10000, TRUE))
ID.Number <- factor(sample(500, 10000, TRUE))
Golden.Trevally <- rbinom(10000, 1, prob =
(c(6, 4, 7, 3)/600)[as.numeric(Behavioural.Activity)] *
c(0.8, 1, 1.2)[as.numeric(Maturity.Status)] *
(as.numeric(ID.Number) / 1000 + 0.75))
mydf2 <- data.frame(ID.Number, Golden.Trevally,
Behavioural.Activity, Maturity.Status)
mod <- glmer(Golden.Trevally ~ Maturity.Status + Behavioural.Activity + (1 | ID.Number),
family = "binomial", data = mydf2)
my_sjplot <- plot_model(mod, "pred", title = "")
my_sjplot$Behavioural.Activity
The solution here is to realize that the object returned by plot_model
is a list containing two ggplot
objects.这里的解决方案是实现plot_model返回的
plot_model
是一个包含两个ggplot
对象的列表。 You are seeing the one for Behavioural.Activity
.您看到的是
Behavioural.Activity
。 It looks the way it does because it has a scale_y_continuous
whose labelling function is labelling the breaks to the nearest percent.它看起来是这样的,因为它有一个
scale_y_continuous
,其标签 function 将中断标记为最接近的百分比。 You can simply over-ride this scale with one of your own:你可以简单地用你自己的规模来覆盖这个规模:
my_sjplot$Behavioural.Activity +
scale_y_continuous(limits = c(0, 0.01),
labels = scales::percent_format(accuracy = 0.01))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.