Reputation: 6682
I would like to change the labels of the y-axis ("Row") from decreasing (top to bottom) to increasing (top to bottom), to correctly match the plotted values. This should be done for any y-axis labels (automatically), not just be manually defining the values at the y-axis (in other words, how can I grab out the used labels on the y-axis, invert their order and then put them back in as labels? how would panel.levelplot() look like?). Also, this should be done without using additional packages.
library(lattice)
A <- outer(1:100, 1:100, FUN = function(x, y) (x+2*y)/300)
levelplot(t(A)[, nrow(A):1], xlab = "Column", ylab = "Row")
The idea is to visually match the structure of a matrix (diagonal going from top left to bottom right). Thanks.
Upvotes: 1
Views: 1904
Reputation: 162341
Just set ylim=c(100,1)
or, better yet, ylim=c(100.5,0.5)
:
## Prepare figures with and without inverted y-axes, for easy comparison
a <- levelplot(t(A)[, nrow(A):1], xlab = "Column", ylab = "Row")
b <- levelplot(t(A)[, nrow(A):1], xlab = "Column", ylab = "Row",
ylim=c(100.5, 0.5))
## Plot figs side-by-side to confirm that this works
library(gridExtra)
grid.arrange(a, b, ncol=2)
Upvotes: 3