[R] Label axis tick marks with a simple function of axis value

Jim Lemon jim at bitwrit.com.au
Wed Apr 9 00:24:30 CEST 2014


On 04/09/2014 02:06 AM, Hurr wrote:
> Don suggested something like this:
> h=c(1,2,3,4,5,6,7,8,9)
> v=c(9,8,7,6,5,4,3,2,1)
> plot(h,v,xaxt='n')
> xat=pretty(h)
> axis(1,at=xat,labels=1/xat)
> But it puts the tick marks at the data-x-locations.
> If the tick locations are not automatic or
> automatically separate from the data locations, then
> I want to tell it where to put them using
> a separate indicator. I am not familiar enough with
> R to find the answer.
> But if it would work, it would be valuable.
>
>
Hi Hurr,
If you want to use pretty:

pretty(1:9)
[1]  0  2  4  6  8 10

you don't necessarily get axis ticks at the same locations as the data 
points. Maybe you want to specify your own axis ticks and use those:

axis_ticks<-c(1,4,7,10)
axis(1,at=axis_ticks,labels=1/axis_ticks)

but that seems too obvious. Could you supply an example of what you want 
to do?

Jim




More information about the R-help mailing list