From dan at bolser.co.uk  Wed Apr 27 01:18:32 2005
From: dan at bolser.co.uk (dan@bolser.co.uk)
Date: Wed Apr 27 01:18:43 2005
Subject: [Rd] postscript (eps) / latex / par(mfg=...) / problem! (PR#7820)
Message-ID: <20050426231832.E9DD2A1E4@slim.kubism.ku.dk>

Full_Name: Dan Freak Bolser
Version: Version 2.0.0  (2004-10-04)
OS: Linux 2.4.20-31.9 (RedHat 9)
Submission from: (NULL) (62.253.128.15)


                                                                                
                                                                        
The same problem I am having has been reported here
                                                                                
                                                                        
http://tolstoy.newcastle.edu.au/R/devel/04a/0344.html
                                                                                
                                                                        
                                                                                
                                                                        
Namely that using par(mfg=...) with a postscript (eps) for inclusion with
latex makes the figure appear upside down and back to front (flipped)!
                                                                                
                                                                        
Converting the dvi to ps makes matters worse (the eps seems to be broken),
however, it appears fine with gv.
                                                                                
                                                                        
Here is (basically) the code I am using...
                                                                                
                                                                        
>dat <- read.table("x.dmp", header=1)
>t(dat)
t(dat)
            1   2   3   4  5  6 7  8 9 10 11 12 13 14 15 16 17 18 19 20
CHAINS      1   2   3   4  5  6 7  8 9 10 11 12 13 14 16 20 23 24 26 28
FREQUENCY 886 792 136 201 16 58 6 21 3  9  3  9  1  4  3  1  1  1  1  1
>
>postscript(
+           "x.eps",
+           width = 6.0,
+           height = 6.0,
+           horizontal = FALSE,
+           onefile = FALSE,
+           paper = "special",
+           )
>
>par(mfg=c(1,1))
>par(mar=c(3,4,1,2))
>plot(dat,type='b')
>
>par(mfg=c(2,1))
>par(mar=c(4,4,0,2))
>plot(dat,type='b', log='y')
>
>dev.off()
                                                                                
                                                                        
                                                                                
                                                                        
Including the resulting file in a latex document like this...
                                                                                
                                                                        
begin{figure}
\centering
\includegraphics[width=\textwidth]{x.eps}
\caption[X]
{
Hello!
}
\label{xFig}
\end{figure}
                                                                                
                                                                        
The result is an upside down (flipped) version of my plot. I tried
rotating 180 degrees (based on similar problems people were having on the
list), but then it just gets worse (most of the plot is off the page). If
I convert the dvi to ps (dvips -Ppdf my.tex.dvi -o my.tex.ps) it gets
worse (a tiny speck where the image should be).
                                                                                
                                                                        
After removing the two mfg commands (which I use to add grid lines (not
shown for clarity)) everything is fine! Some how mfg is snarling things
up.
                                                                                
                                                                        
OK, I just had a brain wave (dont laugh). Here is a diff of the working
eps vs the broken eps...
                                                                                
                                                                        
diff broken working
                                                                                
                                                                        
78a79,80
> %%Page: 1 1
> bp
229c231
< 57.60 43.20 403.20 201.60 cl
---
> 57.60 57.60 403.20 216.00 cl
417c419
< %%Pages: 0
---
> %%Pages: 1
                                                                                
                                                                        
                                                                                
                                                                        
Does that help anyone debug my problem? Like I said, both look identical
via gv, and are 'conceptually' identical in R.
                                                                                
                                                                        
Here are my vitals
                                                                                
                                                                        
Linux 2.4.20-31.9 i686 athlon i386 GNU/Linux
R 2.0.0 (2004-10-04).
GNU Ghostscript 7.05 (2002-04-22)
                                                                                
                                                                        
Anything else you need?
                                                                                
                                                                        
Please help!


[Rd] postscript (eps) / latex / par(mfg=...) / problem! (PR#7820)
dan@bolser.co.uk