Home > Blockchain >  How to change order of plot and strip text in effect plot?
How to change order of plot and strip text in effect plot?

Time:12-19

How do I change the order of the panels in the plot below? For instance I want Sweden, Norway, Australia and USA. I tried to use index.cond=list(c("Sweden", "Norway", "Australia", "USA")) but it does not worked. I also want to change the text in the strips. Instead of country=Sweden I want just Sweden. I tried strip = strip.custom(strip.names=FALSE, strip.levels=TRUE) but it also doesn't worked.
these two methods is what I found in stack but it doesn't helped me to solve my problem.

# data for WVS is in the package
library(MASS) 
library(effects)
wvs.2 <- polr(poverty ~ country*(gender   religion   degree   ns(age, 4)),data = WVS)  

#effect plot
plot(Effect(focal.predictors = c("country","age"), mod = wvs.2, 
          xlevels = list(age = 20:80),
          latent = TRUE),
   rug = FALSE,
   ylim = c(0,3.5))

plot

CodePudding user response:

You can change the order of the panels by changing the order of the factor levels in your data, and you can remove the country= by adding the argument lattice = list(strip = list(factor.names = FALSE)),

library(MASS) 
library(effects)
#> Loading required package: carData
#> lattice theme set by effectsTheme()
#> See ?effectsTheme for details.
library(splines)

data("WVS", package = "carData")

WVS$country <- factor(WVS$country, c("Sweden", "Norway", "Australia", "USA"))

wvs.2 <- polr(poverty ~ country*(gender   religion   degree   ns(age, 4)),
              data = WVS)

#effect plot
plot(Effect(focal.predictors = c("country","age"), mod = wvs.2, 
            xlevels = list(age = 20:80),
            latent = TRUE),
     rug = FALSE,
     lattice = list(strip = list(factor.names = FALSE)),
     as.table = TRUE)
#> 
#> Re-fitting to get Hessian

Created on 2022-12-18 with reprex v2.0.2

  • Related