Search code examples
rlatticebwplot

bwplot axis values are displayed incorrectly


the following code produces a bwplot, but the values on the y axis are 1,2,3,4,5 instead of 10,11,12,13,14. How can I correct this?

library(lattice)
test <- data.frame(c(rep(10,100),rep(11,100),rep(12,100),rep(13,100),rep(14,100))
               ,c(rep(rnorm(n=500,mean=2,sd=1:3))))
names(test) <- c("a","b")
bwplot(a ~ b, test)

Solution

  • bwplot (lattice) expects factors on the left side of the ~. Explicitly convert before plotting

    test$a = as.factor(test$a)
    

    or (exlusive or) use

    bwplot(as.factor(a) ~ b, test)