[R] Titles changing when a plot is redrawn
John Nolan
jpnolan at american.edu
Thu Oct 6 05:01:26 CEST 2011
I ran into a problem with titles on graphs. I wanted a graph with
multiple subplots, with each having a title that involved both
a Greek letter and an identifier for each graph. Below is a
simplified version of code to do this. The graph appears fine,
with the first graph having "i=1" in the title, and the second
graph having "i=2" in the title. However, when I resize the graph,
the plot titles change, with both showing "i=2". The titles also
change when I save the plot to a file using the "File" menu,
then "Save as" in Windows. Is this what should happen? I
always thought that titles are static once the graph is
drawn, and couldn't change.
The problem occurs on some version of R, but not on others.
It does occur with the latest version of R:
> str(R.Version())
List of 13
$ platform : chr "i386-pc-mingw32"
$ arch : chr "i386"
$ os : chr "mingw32"
$ system : chr "i386, mingw32"
$ status : chr ""
$ major : chr "2"
$ minor : chr "13.2"
$ year : chr "2011"
$ month : chr "09"
$ day : chr "30"
$ svn rev : chr "57111"
$ language : chr "R"
$ version.string: chr "R version 2.13.2 (2011-09-30)"
The problem also occurs on: R 2.13.0 on Win32
and Mac (R 2.12.0, x86_64-apple-darwin9.8.0)
The problem DOES NOT occur under R 2.10.0 on Win32.
If the code below is bracketed with pdf("test.pdf")
and dev.off(), the correct labels appear in the file.
This behavior doesn't seem to appear if there is only
one plot.
My guess is that the titles are being reevaluated when
the plot is redrawn, and since the value of i is 2 when
the redraw occurs, both labels get set to "i=2". I guess
"Save as" forces a redraw because a dialog box pops up?
If could be that this behavior is what is intended, and that
somewhere between R 2.10.0 and R 2.13.2 an old bug was fixed.
Or this behavior is not what was intended, and a bug was
introduced. If the former, this should be explained to the user
somewhere. If the latter, can someone track it down and fix?
John Nolan
#-------------------------------------------------
par(mfrow=c(2,1))
for (i in 1:2) {
x <- 1:100
rmse <- sin(x/5) # fake data
plot(x,rmse)
str1 <- bquote( paste("RMSE(",theta,"), ",i==.(i) ))
title( str1 )
}
#-------------------------------------------------
...........................................................................
John P. Nolan
Math/Stat Department
227 Gray Hall
American University
4400 Massachusetts Avenue, NW
Washington, DC 20016-8050
jpnolan at american.edu
202.885.3140 voice
202.885.3155 fax
http://academic2.american.edu/~jpnolan
...........................................................................
More information about the R-help
mailing list