如何在R中将x轴刻度从数字更改为单词

发布于 2025-01-12 10:39:26 字数 518 浏览 5 评论 0原文

我有以下代码:

library(sjPlot)

v1 <- rbinom(100, size=1, p=0.5)
v2 <- rnorm(1:100)
v3 <- rnorm(1:100)
v4<- rbinom(100, size=1, p=0.5)
mydf<- data.frame(v1, v2, v3, v4)

mydf$v4 <- as.factor(mydf$v4)
mydf$v1 <- as.factor(mydf$v1)

mylogit <- glm(v1 ~ v2 + v3 + v4 )
mylogit

sjPlot::plot_model(mylogit, type = "eff", terms = "v4") +
  ggtitle("Country") + theme_set(theme_bw())+
  ylab("") +
  xlab("")

我想要做的是将 x 轴中的 1 和 0 替换为“pre”和“post”。我用了一些方法来改变它们,但它们对我不起作用。

I have the following code:

library(sjPlot)

v1 <- rbinom(100, size=1, p=0.5)
v2 <- rnorm(1:100)
v3 <- rnorm(1:100)
v4<- rbinom(100, size=1, p=0.5)
mydf<- data.frame(v1, v2, v3, v4)

mydf$v4 <- as.factor(mydf$v4)
mydf$v1 <- as.factor(mydf$v1)

mylogit <- glm(v1 ~ v2 + v3 + v4 )
mylogit

sjPlot::plot_model(mylogit, type = "eff", terms = "v4") +
  ggtitle("Country") + theme_set(theme_bw())+
  ylab("") +
  xlab("")

What I want to do is to replace 1 and 0 in my x-axis with "pre" and "post." I used a few methods to change them but they never worked for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灯角 2025-01-19 10:39:26

怎么样:

  plot_model(mylogit, type = "eff", terms = "v4") +
  ggtitle("Country") + theme_set(theme_bw())+
  ylab("") +
  xlab("") + scale_x_continuous(breaks=c(0,0.25,0.5,0.75,1),labels = c("pre",0.25,0.5,0.75,"post"))
  

在此处输入图像描述

How about this:

  plot_model(mylogit, type = "eff", terms = "v4") +
  ggtitle("Country") + theme_set(theme_bw())+
  ylab("") +
  xlab("") + scale_x_continuous(breaks=c(0,0.25,0.5,0.75,1),labels = c("pre",0.25,0.5,0.75,"post"))
  

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文