Reputation: 39
i am wanting to do an xyplot and i have names of schools and their scores. The school names are on y axis and their scores on x axis. Lattice plots go from bottom to top in alphabetical order. I want it to go from A-Z from top to bottom. So if I have a very minimal example:
x <- sample(1:50,100,T)
y <- as.factor(sample(letters,100,T))
xyplot(y~x)
how can i go get it to from A to Z from top to bottom. I have tried rev()
and sort()
and can't seem to get things to change. My grouping variable in the data file are characters so not sure how to reverse the numbers. Any suggestions?
Upvotes: 1
Views: 1533
Reputation: 206232
Factors print out in order of their levels. Just flip the levels
x <- sample(1:50,100,T)
y <- as.factor(sample(letters,100,T))
y <- factor(y, levels=rev(levels(y)))
xyplot(y~x)
Upvotes: 4