Skip to content

Plotmath bug or my misunderstanding?

8 messages · Bert Gunter, David Winsemius, Duncan Murdoch +1 more

#
This is a followup to a recent post on using atop() to obtain
multiline expressions.

My reading of the plotmath docs makes it clear that issuing (in base
graphics) the specification

par(cex = 2)

doubles symbols and regular text in subsequent plotmath expressions.
However, it is unclear to me what specifying cex _within_ the
annotation function using plotmath should do, and the following seems
to want to have it both ways: ignore/obey )or maybe recycle?)

plot(1,type="n", xaxt='n', yaxt='n', ann=FALSE)
 text(1,1,labels=expression(atop(sigma,"some text")),cex = 2)
## obeys the cex specification in symbols and text

HOWEVER

plot(1,type="n", xaxt='n', yaxt='n', ann=FALSE)
 text(1,1,labels=expression(atop(atop(sigma,"some text"),"another
level")),cex = 2)
## ???

For even more fun, try:

plot(1,type="n", xaxt='n', yaxt='n', ann=FALSE)
 text(1,1,labels=expression(atop(atop(sigma,"some text"),"another
level")),cex = 1:2)
##????

So I confess to being flummoxed. Enlightenment would be much appreciated.

Cheers,
Bert
#
Hi Bert,

I think the 'cex=' argument applies to the outermost 'atop()'.
It then applies that size specification to each of the two
components of the atop(a,b). If one of the components is itself
another atop(a,b), then the individual parts are sized downward
to produce the required cex for the unit.

As for the 'cex=1:2' specification, only the first value is used.

Cheers,
Peter Ehlers
On 2012-05-12 14:05, Bert Gunter wrote:
#
On May 12, 2012, at 6:27 PM, Peter Ehlers wrote:

            
Isn't there also a 0.67 factor being applied to whatever was the  
"outside" size prior to being used for the atop arguments? So the  
inner atop arguments get that applied twice if I understand correctly.

text(1,1,labels=expression(atop(
                atop("top level one", "top level two"),
                "another level")
      ) )


I did notice that the cr-linefeed (perhaps unintentionally being  
inserted by a mail client) seemed to be "working" at least on my Mac :

plot(1,1)
text(1,1,labels=expression("another
level")
      )

Whereas it is well known that "\n" will appear as two characters, \n,  
and not be interpreted as a special.
#
On 12-05-13 12:27 AM, David Winsemius wrote:
I think that only works when the newline (which could equally be \n) is 
within a string; if you want a symbol over another symbol you need the atop.

I.e.

plot(1,1)
text(1,1,labels=expression("another\nlevel"))

is the same as what you typed, but

plot(1,1)
text(1,1,labels=expression(paste("another","\n", "level")))

won't do anything useful.

Duncan Murdoch
#
Peter/David:

1. For some reason, I didn't see Peter's reply on r-help.

2. To Peter: Aha!!
Let me play this back to you. In

 text(1,1,labels=expression(atop(atop(sigma,"some text"),"another
level")),cex = 2)

The (outer) whole atop() specification is allocated twice the amount
of space that would be required for the current font size, cex =1.
Then each of the top and bottom is allocated the amount of space
needed within this cex = 2 space. For the inner atop to fit within
that allocated amount of space, its top and bottom must get smaller,
of course. N'est-ce pas?

This makes sense to me!  My misunderstanding is thinking that cex
applied to the individual text components, not the entire expression.
Enlightenment much appreciated.

3. However, this now begs the question of how to keep all text and
symbols the same size, which is really what the OP really wanted (a
way to emulate multiple lines). I'll fool around with this to see what
I come up with now that I'm enlightened -- or see if you or David come
up with something clever.


Cheers,
Bert
On Sat, May 12, 2012 at 9:27 PM, David Winsemius <dwinsemius at comcast.net> wrote:

  
    
#
On May 13, 2012, at 10:43 AM, Bert Gunter wrote:

            
Any cleverness I exhibit on these pages is generally ascribable to my  
R-betters. When faced with a request like this, I just fire up Google  
and generally find an answer from Lumley, Grothendieck, Ligges, or in  
this case, Schwartz (from an rhelp post in 2009). This was the first  
hit that wasn't a link to R documentation with a search on "multiple  
lines expression plotmath r"

# values to pull from using bquote
  X= 2.3
Y= 5.6
txtList <- list("Line # 1",
      "Longer line #2",
       bquote(X == .(X)),
      "and",
       bquote(The~value~of~Y == .(Y)))

plot(1,type="n", xaxt='n', yaxt='n', ann=FALSE)
text(1.2, seq(1.2, 1.1, len=5) , labels=do.call(expression, txtList))

I think this is a fairly generally strategy but I'm certainly willing  
to take a crack at further modifications if desired.
#
Bert: inline
On 2012-05-13 7:43, Bert Gunter wrote:
Yes, that's my understanding. With your text() call above, the
size of "another level" is what text(x,y,lab="another text",cex=2)
will print.
I don't think it's possible to nest atop()s and have all members
of the same cex.

Anyway, atop() is really the wrong tool for this sort of thing.
It can be a useful quick fix, but I usually prefer the 'multiple
lines' approach for its greater flexibility.

Peter Ehlers
#
Peter/David:

Yes, I think this is the general approach for multiple lines in
plotmath expressions. For future reference, a simple canonical example
is:

exl <- list(quote(sigma), "tau",quote(beta))
plot(0:1,0:1,type="n",axes=FALSE)
text(do.call(expression,exl),x=.5,y=seq(.4,.6,by=.1),cex=2)

The points to note are:

1. The plotmath expressions, but not quoted character strings,  in the
list have to be protected from evaluation by quote() (or bquote if
variable values are to be substituted in them);

2. The individual components/lines have to be positioned manually via
x and y; there is no newline ("\n") capability, since plotmath is
"drawing" the expressions.

3. atop()  is NOT the right way to do this.

Thanks to you both for clarifying this for me.

Best,
Bert
On Sun, May 13, 2012 at 9:45 AM, David Winsemius <dwinsemius at comcast.net> wrote: