Search code examples
rplotggplot2panellattice

xyplot : repeated tick marks on all panels


I am plotting an xyplot with panels in R. It looks good, but I would like the tick marks (10, 20, 30, ...) to be repeated in every panel.

Is that possible with xyplot, or should I switch to ggplot (and if so, how)?

Minimal working example:

library(lattice)
productcountry <- rep(c("United Kingdom","USA"),each=20)
productname <- rep(rep(c("Tea","Cornflakes"),each=10),times=2)
productprice <- c(c(10,12,18,26,35,45,50,58,59,60),c(20,25,40,45,46,49,53,55,61,61),c(10,12,16,25,33,41,48,52,56,61),c(25,27,34,40,43,47,50,52,54,55))
productqty <- c(c(33,29,30,35,37,21,25,30,28,34),c(40,34,29,28,25,20,17,14,10,4),c(41,39,32,30,26,23,20,16,15,12),c(22,26,23,19,28,25,26,20,24,22))
elasticitydata <- data.frame(productcountry,productname,productqty,productprice)
colnames(elasticitydata) <- c("Country","Product","Quantity","Price")
elasticityplot <- xyplot(Quantity ~ Price | Country + Product, data = elasticitydata, type = c("g","p","smooth"))

Output:

enter image description here


Solution

  • It's as easy as that:

    update(elasticityplot, scales = list(alternating = 3))
    

    scatterplot

    Note that scales can also be specified inside xyplot, i.e.

    xyplot(..., scales = list(alternating = 3))