# Label axis tick marks with a simple function of axis value Classic List Threaded 13 messages Open this post in threaded view
|

## Label axis tick marks with a simple function of axis value

 How can I label existing axis tick marks with a simple function of axis value like 1/AxisValue? It seems like this should be an operation where I just use the formula.
Open this post in threaded view
|

## Re: Label axis tick marks with a simple function of axis value

 On 04/01/2014 09:25 AM, Hurr wrote: > How can I label existing axis tick marks with a > simple function of axis value like 1/AxisValue? > It seems like this should be an operation where > I just use the formula. > Hi Hurr, You can do this with boxed.labels (plotrix) if you know the position of the axis labels. If not, maybe axis.mult (also plotrix) will help. Jim ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Label axis tick marks with a simple function of axis value

 In reply to this post by Hurr If you want to customize tick mark labels, use the axis() function. Something along the lines of plot(x,y, xaxt='n') xat <- pretty(x) axis(1, at=xat, labels=1/xat) -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 3/31/14 3:25 PM, "Hurr" <[hidden email]> wrote: >How can I label existing axis tick marks with a >simple function of axis value like 1/AxisValue? >It seems like this should be an operation where >I just use the formula. > > > > >-- >View this message in context: >http://r.789695.n4.nabble.com/Label-axis-tick-marks-with-a-simple-function>-of-axis-value-tp4687917.html >Sent from the R help mailing list archive at Nabble.com. > >______________________________________________ >[hidden email] 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. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Label axis tick marks with a simple function of axis value

 Don suggested something like this: h=c(1,2,3,4,5,6,7,8,9) v=c(9,8,7,6,5,4,3,2,1) plot(h,v,xaxt='n') xat=pretty(h) axis(1,at=xat,labels=1/xat) But it puts the tick marks at the data-x-locations. If the tick locations are not automatic or automatically separate from the data locations, then I want to tell it where to put them using a separate indicator. I am not familiar enough with R to find the answer. But if it would work, it would be valuable.
Open this post in threaded view
|

## Re: Label axis tick marks with a simple function of axis value

 On 04/09/2014 02:06 AM, Hurr wrote: > Don suggested something like this: > h=c(1,2,3,4,5,6,7,8,9) > v=c(9,8,7,6,5,4,3,2,1) > plot(h,v,xaxt='n') > xat=pretty(h) > axis(1,at=xat,labels=1/xat) > But it puts the tick marks at the data-x-locations. > If the tick locations are not automatic or > automatically separate from the data locations, then > I want to tell it where to put them using > a separate indicator. I am not familiar enough with > R to find the answer. > But if it would work, it would be valuable. > > Hi Hurr, If you want to use pretty: pretty(1:9)   0  2  4  6  8 10 you don't necessarily get axis ticks at the same locations as the data points. Maybe you want to specify your own axis ticks and use those: axis_ticks<-c(1,4,7,10) axis(1,at=axis_ticks,labels=1/axis_ticks) but that seems too obvious. Could you supply an example of what you want to do? Jim ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Label axis tick marks with a simple function of axis value

 In reply to this post by Jim Lemon This still puts tick marks at data points: h=c(1,2,3,4,5,6,7,8,9) v=c(9,8,7,6,5,4,3,2,1) plot(h,v,xaxt='n') x<-c(1.6,2.6,6.6,9.6,12.9) axis_labels<-1/pretty(x) axis(1,at=pretty(x),labels=axis_labels) How do I get the axis to approx 13 ?
Open this post in threaded view
|

## Re: Label axis tick marks with a simple function of axis value

 On 04/09/2014 01:12 PM, Hurr wrote: > > This still puts tick marks at data points: > h=c(1,2,3,4,5,6,7,8,9) > v=c(9,8,7,6,5,4,3,2,1) > plot(h,v,xaxt='n') > x<-c(1.6,2.6,6.6,9.6,12.9) > axis_labels<-1/pretty(x) > axis(1,at=pretty(x),labels=axis_labels) > How do I get the axis to approx 13 ? > > plot(x,xaxt="n",xlim=c(1,13)) Jim ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Label axis tick marks with a simple function of axis value

 Thanks Jim, Labels for the following are at 0,2,4,6,8,10,12, not data, good. and omitted where lack of room. h=c(1.2,2.4,3.1,4.7,5.3,6.2,7.6,8.8,9.7) v=c(9,8,7,6,5,4,3,2,1) plot(h,v,xaxt='n',xlim=c(-1,13)) x<-c(1.6,2.6,6.6,9.6,12.9) axis_labels<-1/pretty(x) axis(1,at=pretty(x),labels=axis_labels) Suppose I really did want more control, like where and what exactly
Open this post in threaded view
|

## Re: Label axis tick marks with a simple function of axis value

 On 04/09/2014 06:17 PM, Hurr wrote: > Thanks Jim, Labels for the following are at 0,2,4,6,8,10,12, not data, good. > and omitted where lack of room. > > h=c(1.2,2.4,3.1,4.7,5.3,6.2,7.6,8.8,9.7) > v=c(9,8,7,6,5,4,3,2,1) > plot(h,v,xaxt='n',xlim=c(-1,13)) > x<-c(1.6,2.6,6.6,9.6,12.9) > axis_labels<-1/pretty(x) > axis(1,at=pretty(x),labels=axis_labels) > > Suppose I really did want more control, like where and what exactly > If you want to specify the exact values of the ticks for the "at" argument, just remember to extend the x axis on the initial plot to include all x values. If you want to get the missing labels, look at the staxlab function in the plotrix package. Jim ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Label axis tick marks with a simple function of axis value

 What we've covered so far is of great value. For a neater plot, the next step will be to learn how to put numbers with units at each tick mark. I suppose I can form the number-unit string myself in separate code and put the tickmark in a place that I calculate in separate code. But I need to learn the plotting code.
Open this post in threaded view
|

## Re: Label axis tick marks with a simple function of axis value

 On Apr 9, 2014, at 6:17 PM, Hurr wrote: > What we've covered so far is of great value. > For a neater plot, > the next step will be to learn how to put > numbers with units at each tick mark. > I suppose I can form the number-unit string myself in > separate code and put the tickmark in a place that > I calculate in separate code. > But I need to learn the plotting code. It appears that this question has already been answered by Jim Lemon multiple ways. Have you tried his code? Have you followed the various links from the help page of `plot`? Have you constructed a test case and tried to solve this yourself? (He is a much more patient person than I am, but I'm sure he has some minimal expectation of the level of effort he expects from his correspondents.) PLEASE (read more thoroughly?):  (the material at the bottom of every regularly posted item on the list but not seen by Nabble users.) PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. -- David Winsemius Alameda, CA, USA ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.