[R] x-axis tick marks on log scale plot

Duncan Murdoch murdoch.duncan at gmail.com
Thu May 19 15:47:48 CEST 2016


On 19/05/2016 9:40 AM, Brian Smith wrote:
> Hi,
>
> I have a plot with log scale on the axes. How do I add ticks and labels in
> addition to the ones provided by default? Can I specify where I want the
> ticks and labels?
>
> For example:
>
> set.seed(12345)
> x <- sample(1:10000,10)
> y <- sample(1:10000,10)
>
> plot(x,y,log="xy")
>
>
> For me, this plot has tick marks (and labels) at 2000, 4000, 6000, 8000.
> How can I make the axes so that it has marks and labels at 1000 intervals
> (i.e. 2000, 3000, 4000, etc.)

You'll get ticks on side 1 (the x axis) by using

axis(1, at=1000*(2:10))

You'll get labels at some of those locations; R will leave some out, if 
it looks as though the labels will overlap.  Using las=2 will make them 
perpendicular to the axis, and all should be drawn.

Duncan Murdoch



More information about the R-help mailing list