Question

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)
Était-ce utile?

La 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)

Autres conseils

It look alike you will need to convert column a to a character factor

test$a=as.factor(as.character(test$a))
bwplot(a~b, data=test)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top