문제

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)
도움이 되었습니까?

해결책

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)

다른 팁

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top