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)? Thanks in advance. -- r2151
Hi much quicker and better for you is to inspect help pages. ?axis axis(1, at=1:4, labels=c(letters[1:4])) Regards Petr> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of e-letter > Sent: Thursday, February 14, 2013 11:41 AM > To: r-help at r-project.org > Subject: [R] plot custom x axis ticks values > > 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)? > > Thanks in advance. > > -- > r2151 > > ______________________________________________ > 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.
On 14/02/2013, PIKAL Petr <petr.pikal at precheza.cz> wrote:> Hi > > much quicker and better for you is to inspect help pages. > > ?axis > > axis(1, at=1:4, labels=c(letters[1:4]))Had tried, but noticed that the labels created were not positioned equally across the entire axis, but occupied about 50 % (the left half) of the axis. How to change this please?
Hi when I tried your code the labels were positioned at correct positions. Please send some reproducible example. Regards Petr> -----Original Message----- > From: e-letter [mailto:inpost at gmail.com] > Sent: Thursday, February 14, 2013 11:58 AM > To: PIKAL Petr > Cc: r-help at r-project.org > Subject: Re: [R] plot custom x axis ticks values > > On 14/02/2013, PIKAL Petr <petr.pikal at precheza.cz> wrote: > > Hi > > > > much quicker and better for you is to inspect help pages. > > > > ?axis > > > > axis(1, at=1:4, labels=c(letters[1:4])) > > Had tried, but noticed that the labels created were not positioned > equally across the entire axis, but occupied about 50 % (the left > half) of the axis. How to change this please?
> plot(testvalues,ann=FALSE,type='l',yaxt='n',xaxt='n') > par()$usr[1] 0.88 4.12 8.80 41.20 The x axis range is from 0.88 to 4.12, so tick labels at 0, 100, 200, 300 makes no sense. Any axis() command where the 'at' values are within the range of the x axis will work. Even, for example, axis(1, at=c(2.5, 3.7) ) -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 2/14/13 2:41 AM, "e-letter" <inpost at gmail.com> 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)? > >Thanks in advance. > >-- >r2151 > >______________________________________________ >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.
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)) As you may be adding more values after the first set, the same goes for the X axis if there are different numbers of Y values. Jim