Skip to content

Changing graphic titles when using bquote and resizing the graphic window

2 messages · Mathieu Ribatet, Brian Ripley

#
Dear list,

I found a strange behavior of the graphic display when using bquote to set a title to a plot. The problem arise when you manually resize the graphic window using the mouse. It happens on both quartz and x11 devices. Here's a reproducible example:

par(mfrow = c(1,3))
for (i in 1:3){
  title <- as.expression(bquote(gamma[.(i)]))
  plot(1:10, main = title)
}

Once you ran the code, the figure displays as expected --- each title is $\gamma_i$, $i=1, 2, 3$. Now if you resize manually the graphic window using the mouse all the titles will be set to $\gamma_3$.

In case this is useful, here's the ouput of sessionInfo().
R version 2.14.0 (2011-10-31)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

Best,
Mathieu

----------------------------------------------------------------- 
I3M, UMR CNRS 5149
Universite Montpellier II,
4 place Eugene Bataillon
34095 Montpellier cedex 5   France
http://www.math.univ-montp2.fr/~ribatet
Tel: + 33 (0)4 67 14 41 98
#
(Why is this an R-devel topic?)

When you resize a plot (and sometimes when the graph is repainted), the 
display list is replay-ed.  So if you force delayed evaluation, you get 
evaluation when the list is replay-ed.  So the 'strange' thing is that 
you think delaying evaluation is a good idea.  Use substitute, as the R 
help pages advise.  E.g.

par(mfrow = c(1,3))
for (i in 1:3){
   title <- substitute(gamma[j], list(j=i))
   plot(1:10, main = title)
}
On 24/11/2011 08:54, Mathieu Ribatet wrote: