[R] Label axis tick marks with a simple function of axis value

MacQueen, Don macqueen1 at llnl.gov
Sat Apr 12 00:05:27 CEST 2014


You're on the right track, I think.

Try this example:

plot(21:30, xaxt='n')
labs <- paste(1:10,'units',sep='\n')
axis(1, at=1:10, labels=labs, mgp=c(3, 1.75, 0) )

Documentation for the mgp option is found in
  ?par
and it's not something that I would expect someone new to R to find easily.

In my opinion, the philosophy of R is that a lot of basic tools are
provided, and from them the user is expected to customize and construct
precisely what they want. Although, many of the R packages available from
CRAN exist because someone wanted to pre-write some fancy options for
users to choose from.

Of course, since all the units are the same in my example, it might make
more sense to put the units in the axis label, such as:

  plot(21:30, xlab='Units')

Note a little "trick" in that in the above example that might be
unexpected. I didn't supply both x and y. When only one of them is
supplied, it is interpreted as being y values. Since there are 10 of them,
it is as if it were:
  plot(1:10, 21:30)

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 4/9/14 6:17 PM, "Hurr" <hill0093 at umn.edu> 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.
>
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Label-axis-tick-marks-with-a-simple-function
>-of-axis-value-tp4687917p4688498.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>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