I think that there may be a problem with the way
bquote(), for() and savePlot() play together in
the OP's example (multiple plots on a windows device;
bquote using the loop index).
Here's a version using replayPlot():
## show mu with subscripts 4 and 9:
x11()
par(mfrow = c(2,1))
for (i in c(4, 9)) {
plot(0, 0, main = bquote(mu[.(i)]))
}
## now record and replay:
z <- recordPlot()
replayPlot(z)
## both subscripts are now 9
Simple workarounds are:
1. As Uwe and Dennis show, for saving to file,
use the appropriate device.
2. For recalling plots (e.g. with recording turned on),
a) use substitute() instead of bquote() or
b) insert something like
i <- i
before the plot() call.
sessionInfo()
R version 2.13.0 Patched (2011-05-24 r55981)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252
[3] LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=English_Canada.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
Peter Ehlers
On 2011-06-22 22:14, Dennis Murphy wrote:
Hi:
As Uwe suggested...
pdf('testgraph.pdf')
layout( matrix( 1:2 , nrow=2 ) )
for ( i in 1:2 ) {
plot( 0 , 0 , xlab=bquote(mu[.(i)]) )
}
dev.off()
postscript('testgraph.ps')
layout( matrix( 1:2 , nrow=2 ) )
for ( i in 1:2 ) {
plot( 0 , 0 , xlab=bquote(mu[.(i)]) )
}
dev.off()
png('testgraph.png')
layout( matrix( 1:2 , nrow=2 ) )
for ( i in 1:2 ) {
plot( 0 , 0 , xlab=bquote(mu[.(i)]) )
}
dev.off()
The three graphs look the same (although the PS graph is rotated to
landscape while the other two are portrait). The main point is that
mu_1 and mu_2 show up correctly in the two panels in all three graphs
(at least on my viewers).
The following thread from last January describes some of the problems
that certain viewers have with Greek letters, which appear to be
viewer and platform dependent:
http://r-project.markmail.org/search/?q=pdf%20incorrect#query:pdf%20incorrect+page:2+mid:egmb6utulrxgcznw+state:results
I'm guessing that I've seen about a half dozen or so similar posts in
this forum over the past year and a half, so you can check the list
archives for related problems.
HTH,
Dennis
On Wed, Jun 22, 2011 at 8:07 PM, John Kruschke<johnkrusc...@gmail.com> wrote:
Here's a fairly minimal-case example in which the saved EPS does not match
the screen. The error comes when using bquote(.(i)) instead of bquote(1), as
demonstrated by the two minimally different cases below. Very strange. Any
clues as to why?
#---------------- begin -------------------
# Version A. X axis labels have subscripts as constants. EPS is correct.
windows()
layout( matrix( 1:2 , nrow=2 ) )
plot( 0 , 0 , xlab=bquote(mu[1]) )
plot( 0 , 0 , xlab=bquote(mu[2]) )
savePlot( file="SavePlotTestA.eps" , type="eps" ) # Axis labels are correct
in EPS.
# Version B. X axis labels have subscripts as variable index. EPS is wrong!
windows()
layout( matrix( 1:2 , nrow=2 ) )
for ( i in 1:2 ) {
plot( 0 , 0 , xlab=bquote(mu[.(i)]) )
}
savePlot( file="SavePlotTestB.eps" , type="eps" ) # X-AXIS OF PLOT 1 IS
WRONG IN EPS.
#-------------- end ---------------------
Thanks!
John K. Kruschke, Professor
<http://www.indiana.edu/%7Ekruschke/DoingBayesianDataAnalysis/>
2011/6/22 Uwe Ligges<lig...@statistik.tu-dortmund.de>
On 22.06.2011 13:50, John Kruschke wrote:
The error happens when using the savePlot() command, like this:
savePlot( file="TestSavePlot.eps" , type="eps" )
savePlot( file="TestSavePlot.jpg" , type="jpg" )
Well, plot directly into a device, for postscript:
postscript("estSavePlot.eps", additionalArguments .....)
plot(1:10)
dev.off()
Uwe Ligges
The images in the two saved files are not the same, with the JPG being
correct but the EPS being wrong.
When you suggest "starting separate devices explicitly", what do you mean?
(I've skimmed through the results of ??device, but can't make sense of
it.)
Thank you!
John K. Kruschke, Professor
2011/6/22 Uwe
Ligges<lig...@statistik.tu-**dortmund.de<lig...@statistik.tu-dortmund.de>
I guess you use the menu to save the plots from your Windows device into
files rather than starting separate devices explicitly?
If so, please use explicit calls to the devices and everything happens as
you define it.
Uwe Ligges
On 22.06.2011 04:31, John Kruschke wrote:
When I save a particular plot as JPG or BMP, the saved image is an
accurate
copy of that plot.
But when I save the same plot as EPS or PDF, some text elements are
incorrectly altered.
An example is attached. Notice in the top middle and top right panels,
the
x-axis labels have correct subscript 1 in the JPG, but incorrect
subscript
2
in the EPS.
I'm using R 2.13.0 on Windows 7.
Any clues regarding the source of this error and its solution would be
appreciated. For example, are there EPS/PDF device drivers that need to
be
separately updated?
Many thanks.
John K. Kruschke, Professor
<http://www.indiana.edu/%****7Ekruschke/****DoingBayesianDataAnalysis/<
htt**p://www.indiana.edu/%**7Ekruschke/**DoingBayesianDataAnalysis/<http://www.indiana.edu/%7Ekruschke/DoingBayesianDataAnalysis/>
______________________________****________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/****listinfo/r-help<https://stat.ethz.ch/mailman/**listinfo/r-help>
<https://stat.**ethz.ch/mailman/listinfo/r-**help<https://stat.ethz.ch/mailman/listinfo/r-help>
PLEASE do read the posting guide http://www.R-project.org/**
posting-guide.html<http://www.**R-project.org/posting-guide.**html<http://www.R-project.org/posting-guide.html>
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
______________________________________________
R-help@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.
______________________________________________
R-help@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.
______________________________________________
R-help@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.