[R] custom tick labels on image
pieterprovoost at gmail.com
Thu Jul 6 19:20:25 CEST 2006
Prof Brian Ripley schreef:
> On Thu, 6 Jul 2006, Pieter Provoost wrote:
>> I'm trying to visualise a matrix using image(), and I would like to add
>> the row and column names as tick labels. I tried adding an axis, but the
>> problem is that this axis goes from 0 to 1 which results in labels being
>> added starting at the far right end of the axis.
>> image(t(data), col = terrain.colors(20), axes=FALSE)
>> axis(3, at = 1:length(colnames(data)), labels=colnames(data))
>> How can I do this better?
> It is probably easiest to supply x and y when calling image, as in the
> final example on the help page. (And BTW, ncol() gives the number of
> columns more readily than length(colnames()).)
Thanks, this worked fine. One additional question: how can I rotate the
labels so they all can be displayed? Srt doesn't seem to work.
x <- (1:nrow(data))
y <- (1:ncol(data))
image(y, x, t(data), col = heat.colors(20),
axis(3, at = 1:ncol(data), labels=colnames(data),srt=45,tick=FALSE)
axis(2, at = 1:nrow(data), labels=rownames(data),srt=45,tick=FALSE)
More information about the R-help