Search code examples
rsjplot

How to change x axis scale from numbers to words in R


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.


Solution

  • 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