[R] axes labeling

Jim Lemon jim at bitwrit.com.au
Fri Dec 21 03:38:07 CET 2012

On 12/21/2012 07:12 AM, Sam Steingold wrote:
>> * David L Carlson<qpneyfba at gnzh.rqh>  [2012-12-20 13:58:00 -0600]:
>> It is possible, but only by using axis() since you can specify axis breaks
>> in a plot command, but not the labels. You can ignore most of the axis()
>> options so the commands are pretty simple:
>> plot(x=c(1, 1000000), y=c(1, 1000000), xlab="x", ylab="y",
>>       xaxt="n", yaxt="n", las=2)
>> pos<- c(0, 200000, 400000, 600000, 800000, 1000000)
>> lbl<- c("0", "200k", "400k", "600k", "800k", "1000k")
>> axis(1, pos, lbl)
>> axis(2, pos, lbl)
> That's what I meant when I said "too much control".
> I am happy with the way R selects positions.
> All I want is a say in the way R formats those positions.
> Think in terms of 1000000 being a variable.
> To use axis, I will need to write a map from variable range to axis tick
> positions first, and then sapply my formatting to the positions.
Hi Sam,
You can use the "pretty" function to get the default positions of the 
axis labels by passing the range of the values:

[1] 0e+00 2e+05 4e+05 6e+05 8e+05 1e+06

Then you can pass these values to the axis function with your labels 
(0k, 200k, ...)


More information about the R-help mailing list