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

Jim Lemon jim at bitwrit.com.au
Wed Apr 9 10:22:20 CEST 2014


On 04/09/2014 06:17 PM, Hurr wrote:
> Thanks Jim, Labels for the following are at 0,2,4,6,8,10,12, not data, good.
> and omitted where lack of room.
>
> h=c(1.2,2.4,3.1,4.7,5.3,6.2,7.6,8.8,9.7)
> v=c(9,8,7,6,5,4,3,2,1)
> plot(h,v,xaxt='n',xlim=c(-1,13))
> x<-c(1.6,2.6,6.6,9.6,12.9)
> axis_labels<-1/pretty(x)
> axis(1,at=pretty(x),labels=axis_labels)
>
> Suppose I really did want more control, like where and what exactly
>
If you want to specify the exact values of the ticks for the "at" 
argument, just remember to extend the x axis on the initial plot to 
include all x values. If you want to get the missing labels, look at the 
staxlab function in the plotrix package.

Jim




More information about the R-help mailing list