2

So I'm making correlation-matrix-like plots using levelplot similar to this (taken from: Plot correlation matrix into a graph):

library(lattice)

#Build the horizontal and vertical axis information
hor <- c("214", "215", "216", "224", "211", "212", "213", "223", "226", "225")
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))

I would like to add labels to each of the top (second) x-axis ticks. Does anyone know how to accomplish this?

Thank you,

Kai

Community
  • 1
  • 1
foxandsticks
  • 349
  • 3
  • 9

1 Answers1

1

You could do this by adding scales=list(alternating=3) to your call of levelplot

If you look up the help for levelplot, for some information, you are referred to xyplot (and others). It is in the xyplot help page, you find a description of scales and therein alternating. Alternating controls the location of the tick labels and can take 4 values:

  • 0 (none),
  • 1 (bottom/left),
  • 2 (top/right),
  • 3 (both).

Here is the call to levelplot that gives you ticks at all sides:

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(alternating=3))
KoenV
  • 4,113
  • 2
  • 23
  • 38
  • Thank you! This solution duplicated my primary x-axis on the secondary x-axis. I would actually like to display a different set of labels on the secondary x-axis. Is this possible? – foxandsticks Apr 19 '17 at 20:04
  • 1
    @foxandsticks My pleasure! Regarding your latest question, I have to investigate this, and I don't have time today. I suggest you **open a new question**, with data and code, and with a description what you already discovered/solved (like the above). This way, you may attract attention from other people. I will upvote your new question when I see it passing. Good Luck! – KoenV Apr 20 '17 at 07:51
  • Many thanks @KoenV! A new questions has been posted here: http://stackoverflow.com/questions/43526149/add-different-labels-to-secondary-x-axis-of-levelplot-in-lattice-in-r – foxandsticks Apr 20 '17 at 17:29