[R] distance betwenn axis and axis annotation

Duncan Murdoch murdoch at stats.uwo.ca
Wed Feb 18 14:37:02 CET 2009


On 18/02/2009 7:50 AM, Mark Difford wrote:
> Duncan Murdoch wrote:
> 
>>> I don't think you can do this directly, but you can do it using mtext.
> 
> This is not correct.

It was correct at the time I wrote it.  Of course things have changed 
now that you and Dimitris have been so helpful:  now I *do* think you 
can do it directly.


  You can, as Dimitris has already shown. See ?par (sub
> mgp). The difficulty arises if you want only one set of axes changed, which
> is not what was requested.

There's no real difficulty there: axis takes an mgp arg as well.  So you 
can plot without axes, then add one axis with one mgp value, and the 
other axis with a different one.

Duncan Murdoch


> 
> ## Example using your "example"
> par(mfrow = c(1, 2))
> x <- 1:10
> y <- rnorm(10)
> 
> plot(x,y, axes=F)
> box()
> at <- pretty(x)
> min <- par("usr")[1]
> max <- par("usr")[2]
> at <- at[ at >= min & at <= max]  # pretty extends the range
> axis(1, at=at, labels=FALSE)
> mtext(at, side=1, at=at, line=3)
> 
> plot(x, y, mgp = c(3, 3, 0))
> 
> Regards, Mark.
> 
> 
> Duncan Murdoch-2 wrote:
>> Luis Ridao Cruz wrote:
>>> R-help,
>>>
>>> How can I specify the distance between the axis and axis annotation?
>>>
>>>
>>>   
>> I don't think you can do this directly, but you can do it using mtext.  
>> For example:
>>
>> x <- 1:10
>> y <- rnorm(10)
>>
>> plot(x,y, axes=F)
>> box()
>> at <- pretty(x)
>> min <- par("usr")[1]
>> max <- par("usr")[2]
>> at <- at[ at >= min & at <= max]  # pretty extends the range
>> axis(1, at=at, labels=FALSE)
>> mtext(at, side=1, at=at, line=3)
>>
>> Duncan Murdoch
>>
>> ______________________________________________
>> 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