[R] plot custom x axis ticks values

e-letter inpost at gmail.com
Fri Feb 15 09:28:14 CET 2013


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



More information about the R-help mailing list