Search code examples
rlattice

How to show the number in R lattice package


We use R 4.0.5, lattice 0.20-38, MacOS 10.14.5.

library("lattice")
xyplot(Ozone ~ Temp | Month,
layout=c(1,5),
data=airquality
)

We got the below figure based on this code. enter image description here

We want to change the name of each figure "Month" to the number of Month. The composite (damy) image is shown below. How should we do?

enter image description here


Solution

  • Change the month column to factor.

    library(lattice)
    
    lattice::xyplot(Ozone ~ Temp | Month,
           layout=c(1,5),
           data = transform(airquality, Month = factor(match(Month, unique(Month))))
    )
    

    enter image description here

    Note that in data Month value is from 5 to 9 but since you want labels from 1 to 5 we use match and unique to get that.