[英]How to invert the order of the y-axis labels in a levelplot?
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. 我想将y轴(“行”)的标签从减少(从上到下)更改为增加(从上到下),以正确匹配绘制的值。 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?).
这应该对任何y轴标签(自动)进行,而不仅仅是手动定义y轴上的值(换句话说,我如何在y轴上抓取使用过的标签,反转它们的顺序然后把它们作为标签放回来?panel.levelplot()怎么样?)。 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.
谢谢。
Just set ylim=c(100,1)
or, better yet, ylim=c(100.5,0.5)
: 只需设置
ylim=c(100,1)
或者更好的是, 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.