[R] plot custom x axis ticks values

Duncan Murdoch murdoch.duncan at gmail.com
Fri Feb 15 10:30:30 CET 2013


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))

is kind of hard to interpret.

Duncan Murdoch



More information about the R-help mailing list