R 如何更改sjPlot软件包中的x轴比例?
我正在使用R 如何更改sjPlot软件包中的x轴比例?,r,ggplot2,plot,sjplot,R,Ggplot2,Plot,Sjplot,我正在使用sjPlot软件包。我正在绘制线性模型的预测值,类似于以下示例: #R Version: 3.6.2 set.seed(1993) x <- seq(1980, 2018, 2) y <- runif(length(x), 1,100) df <- data.frame(x,y) library(ggplot2) library(sjPlot) Results <- lm(y ~ as.factor(x), data = df); summary(Res
sjPlot
软件包。我正在绘制线性模型的预测值,类似于以下示例:
#R Version: 3.6.2
set.seed(1993)
x <- seq(1980, 2018, 2)
y <- runif(length(x), 1,100)
df <- data.frame(x,y)
library(ggplot2)
library(sjPlot)
Results <- lm(y ~ as.factor(x), data = df); summary(Results)
plot_model(Results, type = "pred", terms = c("x"))
如何将x轴重新缩放为4,而不是2
更新
x的比例已经存在。为“x”添加另一个刻度,它将替换现有刻度。
plot\u模型的输出。无论我使用scale\ux\u continuous
还是scale\ux\u discrete
,都是一样的
您好,我的代码很好用。我确实收到了一个警告,“x”刻度已经存在,并且正在被覆盖,但输出绘图有分隔符和标签,分隔为4。您是否收到不同的特定错误/警告?你的绘图输出是什么样子的?嗨!非常感谢您的回复。我更新了这个问题,以说明当我从
sjPlot
包调用plot\u model
时,我的绘图输出是什么样子的。它会同时删除轴标签。使用缩放x_离散
时,会得到与您相同的结果;但是,如果我返回到scale\u x\u continuous
,则该比例将返回,正如您所期望的那样。我不确定是否遵循了该比例<当我将其作为ggplot
命令的一部分调用时,code>scale\u x_continuous可以完美地工作。当我使用sjPlot
函数plot\u model
时,它不工作。也许我应该检查sjPlot
包中的更新?
#This works in ggplot:
ggplot(df, aes(x= x, y=y))+
geom_point() +
scale_x_continuous("Cycle", labels = seq(1980, 2018, 4), breaks = seq(1980, 2018, 4))
#But it doesn't work in sjPlot package -- as either scale_x_continuous
plot_model(Results, type = "pred", terms = c("x")) +
scale_x_continuous("Cycle", labels = seq(1980, 2018, 4), breaks = seq(1980, 2018, 4))
#or either scale_x_discrete
plot_model(Results, type = "pred", terms = c("x")) +
scale_x_discrete("Cycle", labels = seq(1980, 2018, 4), breaks = seq(1980, 2018, 4)