Re: [R] custom tick labels on image

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri 07 Jul 2006 - 03:55:08 EST

On Thu, 6 Jul 2006, Pieter Provoost wrote:

> Prof Brian Ripley schreef:
>> On Thu, 6 Jul 2006, Pieter Provoost wrote:
>>
>>> Hi,
>>>
>>> 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.

?axis says

      ...: other graphical parameters may also be passed as arguments to
           this function, particularly, 'cex.axis', 'col.axis' and
           'font.axis' for axis annotation, 'mgp' and 'xaxp' or 'yaxp'
           for positioning, 'tck' or 'tcl' for tick mark length and
           direction, 'las' for vertical/horizontal label orientation,
           or 'fg' instead of 'col', see 'par' on these.

so you need to use las and accept 0/90/etc.

>
> x <- (1:nrow(data))
> y <- (1:ncol(data))
> image(y, x, t(data), col = heat.colors(20),
> axes=FALSE,xlab="",ylab="",srt=45)
> 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)
>
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Jul 07 03:59:25 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 07 Jul 2006 - 04:15:42 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.