You may also want to look at the cnvrt.coords function in the TeachingDemos
package. It may be a bit simpler than mixing grid and base.
-----Original Message-----
From: "S?bastien" <pomchip at free.fr>
To: "Prof Brian Ripley" <ripley at stats.ox.ac.uk>
Cc: "R-help" <r-help at stat.math.ethz.ch>
Sent: 9/3/07 7:46 PM
Subject: Re: [R] Different behavior of mtext
Thanks for the information on gridBase, I could solve my problem using
the 'baseViewports' function and by replacing mtext by grid.text (with
coordinates adjustments).
Sebastien
Prof Brian Ripley a ?crit :> On Mon, 3 Sep 2007, S?bastien wrote:
>
>> Ok, the problem is clear now. I did not get that
'user-coordinates'
>> was refering to par("usr"), when I read the help of mtext. If
I may
>> ask you some additional questions:
>> - you mentioned a missing unit() call ; at which point should it be
>> done in my code examples ?
>
> Before it is used. The problem is that I believe more than one
> package has a unit() function.
>
>> - could you give me some advices or helpful links about how to set up
>> a grid viewport ? - and finally, probably a stupid question: is a
>> gridview automatically set up when a plotting function is called ?
>
> If you want to mix grid and base graphics, you need package gridBase,
> but really I would not advise a beginner to be using grid directly
> (that is, not via lattice to ggplot*).
>
>
>> Sebastien
>>
>> PS: To answer to your final question, my goal is to center a block of
>> legend text on the device but to align the text to the left of this
>> block.
>>
>> Prof Brian Ripley a ?crit :
>>> On Sun, 2 Sep 2007, S?bastien wrote:
>>>
>>>> Dear R Users,
>>>>
>>>> I am quite surprised to see that mtext gives different results
when it
>>>> is used with 'pairs' and with "plot'. In the
two following codes, it
>>>> seems that the 'at' argument in mtext doesn't
consider the same
>>>> unit system.
>>>
>>> It is stated to be in 'user coordinates'. Your code does
not work
>>> because unit() is missing. If you mean the one from package grid,
>>> "npc" is not user coordinates (and refers to a grid
viewport which
>>> you have not set up and coincidentally is the same as the initial
>>> user coordinate system to which pairs() has reverted).
>>>
>>> Try par("usr") after your pairs() and plot() calls to see
the
>>> difference.
>>> Plotting a 2x2 array of plots _is_ different from plotting one, so
>>> this should be as expected.
>>>
>>> Since centring is the default for 'adj', it is unclear what
you are
>>> trying to achieve here.
>>>
>>>> I would appreciate your comments on this issue.
>>>>
>>>> Sebastien
>>>>
>>>> ##### Pairs
>>>>
>>>> mydata<-data.frame(x=1:10,y=1:10)
>>>>
>>>> par(cex.main=1, cex.axis=1, cex.lab=1, lwd=1,
>>>> mar=c(5 + 5,4,4,2)+0.1)
>>>>
>>>> pairs(mydata,oma=c(5 + 5,4,4,2))
>>>>
>>>> mylegend<-c("mylegend A","mylegend
B","mylegend C","mylegend test")
>>>> mylegend.width = strwidth(mylegend[which.max(nchar(mylegend))],
>>>> "figure")
>>>>
>>>> for (i in 1:4) {
>>>> mtext(text=mylegend[i],
>>>> side = 1,
>>>> line = 3+i,
>>>> at = unit((1-mylegend.width)/2,"npc"),
# centers the
>>>> legend at the bottom
>>>> adj=0,
>>>> padj=0)}
>>>>
>>>> ##### plot
>>>>
>>>> mydata<-data.frame(x=1:10,y=1:10)
>>>>
>>>> par(cex.main=1, cex.axis=1, cex.lab=1, lwd=1,
>>>> mar=c(5 + 5,4,4,2)+0.1)
>>>>
>>>> plot(mydata,oma=c(5 + 5,4,4,2))
>>>>
>>>> mylegend<-c("mylegend A","mylegend
B","mylegend C","mylegend test")
>>>> mylegend.width = strwidth(mylegend[which.max(nchar(mylegend))],
>>>> "figure")
>>>>
>>>> for (i in 1:4) {
>>>> mtext(text=mylegend[i],
>>>> side = 1,
>>>> line = 3+i,
>>>> at = unit((1-mylegend.width)/2,"npc"),
# should
>>>> center the legend at the bottom but doesn't do it !
>>>> adj=0,
>>>> padj=0)}
>>>
>>
>
______________________________________________
R-help at stat.math.ethz.ch 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.