[R] plot custom x axis ticks values
PIKAL Petr
petr.pikal at precheza.cz
Fri Feb 15 14:55:17 CET 2013
Hi
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of e-letter
> Sent: Friday, February 15, 2013 11:37 AM
> To: Duncan Murdoch
> Cc: r-help at r-project.org
> Subject: Re: [R] plot custom x axis ticks values
>
> On 15/02/2013, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
> > On 13-02-15 3:28 AM, e-letter wrote:
> >> On 15/02/2013, Jim Lemon <jim at bitwrit.com.au> wrote:
> >>> On 02/14/2013 09:41 PM, e-letter wrote:
> >>>> Readers,
> >>>>
> >>>> For this data set:
> >>>>
> >>>> testvalues<-c(10,20,30,40)
> >>>>
> >>>> How to amend the plot instruction:
> >>>>
> >>>> plot(testvalues,ann=FALSE,type='l',yaxt='n',xaxt='n')
> >>>>
> >>>> so that x axis ticks labels can be added to existing graph with
> >>>> arbitrary value such as 0,100,200,300)?
> >>>>
> >>> Hi r2151,
> >>> If you want the labels to fit on the axis you will have to include
> >>> this information in the call to "plot":
> >>>
> >>> plot(testvalues,ann=FALSE,type='l',yaxt='n',xaxt='n',ylim=c(0,300))
> >>> axis(2,at=c(0,100,200,300))
> >>>
> >>
> >> plot(testvalues,ann=FALSE,type='l',yaxt='n',xaxt='n',xlim=c(0,300))
> >> axis(1,at=c(0,100,200,300))
> >>
> >> The use of 'xlim' makes the graph unacceptable. Instead, it would be
> >> better to plot:
> >>
> >> plot(testvalues,ann=FALSE,type='l',yaxt='n')
> >>
> >> The x-axis shows tick marks '1.0', '1.5', ...
> >>
> >> It is required to replace these values with custom values (e.g. 10,
> 20...
> >> etc.)
> >
> > Why not rescale the values before plotting, and use the automatic
> ticks?
> > You can lie about the user scale, but it doesn't always give a
> > helpful plot, e.g.
> >
> > axis(1, at=1:4, labels=c(100, 300, 400, 200))
> >
>
> Tried, but realised that this works when the vectors for 'at' and
> 'labels' are equal size. For a data set of e.g. 10 values, syntax error
> returns.
It is rather twisted idea to expect that you say to R:
Please, put 10 labels to x axis at 4 positions.
and expect that the program will not complain.
Maybe you shall consult axis help page, which clearly says:
at - the points at which tick-marks are to be drawn. Non-finite (infinite, NaN or NA) values are omitted. By default (when NULL) tickmark locations are computed, see 'Details' below.
labels - this can either be a logical value specifying whether (numerical) annotations are to be made at the tickmarks, or a character or expression vector of labels to be placed at the tickpoints. (Other objects are coerced by as.graphicsAnnot.) If this is not logical, at should also be supplied and of the same length. If labels is of length zero after coercion, it has the same effect as supplying TRUE.
Regards
Petr
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list