Add Different Labels to Secondary X-Axis of Levelplot in Lattice in R

淺唱寂寞╮ 提交于 2019-12-22 09:47:41

问题


I've managed to label the secondary X-axis in a levelplot using scale=list((alternating=3)) as solved by @KoenV here: How to Add Labels to Top X-Axis of Levelplot in Lattice Package

Now this duplicates the primary X-axis labels onto the secondary X-axis as can be seen by running the code below. However, I need to add different labels to the secondary X-axis.

Does anyone know how to do this?

In the example below I would like to have 'hor' as the primary X-axis labels and 'hor2' as the secondary X-axis labels.

library(lattice)

#Build the horizontal and vertical axis information
hor <- c("214", "215", "216", "224", "211", "212", "213", "223", "226", "225")
hor2 <- paste("5", hor, sep="")
ver <- paste("DM1-", hor, sep="")

#Build the fake correlation matrix
nrowcol <- length(ver)
cor <- matrix(runif(nrowcol*nrowcol, min=0.4), nrow=nrowcol, ncol=nrowcol, dimnames = list(hor, ver))
for (i in 1:nrowcol) cor[i,i] = 1

#Build the plot
rgb.palette <- colorRampPalette(c("blue", "yellow"), space = "rgb")
levelplot(cor, main="stage 12-14 array correlation matrix", xlab="", ylab="", col.regions=rgb.palette(120), cuts=100, at=seq(0,1,0.01), scales=list(x=list(at=1:10, labels=hor, rot=90, alternating=3), y=list(at=1:10, labels=ver)))

Thank you!

来源:https://stackoverflow.com/questions/43526149/add-different-labels-to-secondary-x-axis-of-levelplot-in-lattice-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!