[R] labeling abscissa using a function of the plotted scale

David Winsemius dwinsemius at comcast.net
Thu Oct 24 22:07:04 CEST 2013


On Oct 24, 2013, at 7:00 AM, Hurr wrote:

> Thanks Jim, maybe now I can start learning.
> Here is a run of my trying to learn:
>> xvalue<-c(5.2,1.3,9.7,2.8,8.1,4.7,6.6,7.4)
>> yvalue<-c(9,3,4,7,2,5,3,6)
>> plot(xvalue,yvalue)
>> axis(1,at=NULL,labels=1/xvalue,digits=5)
> Error in axis(1, at = NULL, labels = 1/xvalue, digits = 5) :
>  'labels' is supplied and not 'at'
> In addition: Warning message:
> In axis(1, at = NULL, labels = 1/xvalue, digits = 5) :
>  "digits" is not a graphical parameter
>> 
> Why can't R automatically compute the spacing when I use the formula?

I don't see any formula. If you are talking about the expression `1/xvalue`, it is going to be a decimal fraction and it will be coerced to a character value before being assigned to 'labels'. As explained in the help page for `axis`, when "at" is left as NULL, the positions will be computed from par("xaxt"). But you gave only a numeric argument to labels and did not tell axis where you wanted these values were to be placed. If those values were interpreted as being positions they would have been off the left side of the "paper".

 If you don't like the way 'axis' works, you are welcome to write a new axis function that processes numeric arguments to labels differently. But in this case you appear to think that R kept a record someplace of the argument to x in the preceding plot. _That_ is wishful thinking on your part. If you want a plotting paradigm that may record x and y values, then look at lattice or ggplot2. Base graphics is mostly ( memoryless ) ink-on-paper, although there may be some information accessible via `par`.

> How can I specify n-digits or width instead of round or nothing? 

?sprintf
?formatC
> 
-- 

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list