Skip to content

Problem with figure size when embedding fonts

3 messages · Frank E Harrell Jr, Paul Johnson

#
Dear Colleagues:

I need to make a graphic that uses the Nimbus rather than Helvetica font 
family so that the font can be embedded in the encapsulated postscript 
file.  This is to satisfy a requirement from a journal for electronic 
submission of figures.  I do the following:

postscript('lowess.eps', onefile=FALSE, pointsize=18, horizontal=FALSE,
            family='NimbusSan')
spar(mfrow=c(3,2))
. . .
dev.off()

At this point lowess.eps looks fine.  When I run:
embedFonts('lowess.eps') or
embedFonts('lowess.eps', options='-sPAPERSIZE=letter')

the figures are wider and the right panel of the 3x2 matrix of plots 
expands past the paper edge.  Advice welcomed.

Thanks
Frank


platform       i486-pc-linux-gnu
arch           i486
os             linux-gnu
system         i486, linux-gnu
status
major          2
minor          8.1
year           2008
month          12
day            22
svn rev        47281
language       R
version.string R version 2.8.1 (2008-12-22)
1 day later
#
On Sat, Mar 14, 2009 at 1:51 PM, Frank E Harrell Jr
<f.harrell at vanderbilt.edu> wrote:
Hello Frank:

This is an interesting post. I've not played with this until you
brought it to my attention.

I made a little progress.  It appears to me either that there is
something wrong with embedFonts as applied to postscript files or you
and I need to learn a lot of ghostscript options.

I created a small test and I see the same problem you do--the margins
bump if you embed the fonts. I think the problem may be worse than
that, it looks like the embedFonts wrecks the bounding box of the eps
file.

Do this:

 x <- rnorm(100)
 y <- rnorm(100)
 ml <- loess(y~x)
 plot(x,y)
 lines(ml)
 postscript('lowess.eps', onefile=FALSE, pointsize=18,
horizontal=FALSE, family="NimbusSan")
 plot(x,y)
 lines(ml)
 text (-1,1,"Really big writing")
 dev.off()

Copy "lowess.eps" to a safe place, then run

embedFonts("lowess.eps")

when you compare the two eps files, the margins are quite different.

I see the difference more sharply when I add the features I usually
have in postscript:


postscript('lowess.eps', onefile=FALSE, pointsize=18,
horizontal=FALSE, family="NimbusSan",
height=6,width=6,paper="special")
 plot(x,y)
 lines(ml)
 text(-1,1, "Really  big writing"
 dev.off()

If you run that, save a copy of lowess.eps, then run embedFonts, you
see the new lowess.eps no longer has the proper bounding box.

Here's the top of lowess-orig.eps

%!PS-Adobe-3.0 EPSF-3.0
%%DocumentNeededResources: font NimbusSanL-Regu
%%+ font NimbusSanL-Bold
%%+ font NimbusSanL-ReguItal
%%+ font NimbusSanL-BoldItal
%%+ font StandardSymL
%%Title: R Graphics Output
%%Creator: R Software
%%Pages: (atend)
%%BoundingBox: 0 0 432 432
%%EndComments
%%BeginProlog

On the other hand, the one that results from the embedFonts is not EPS
anymore, and the bounding box is, well, confusing.


%!PS-Adobe-3.0
%%Pages: (atend)
%%BoundingBox: 0 0 0 0
%%HiResBoundingBox: 0.000000 0.000000 0.000000 0.000000
%.................................................
%%Creator: GPL Ghostscript 863 (pswrite)
%%CreationDate: 2009/03/15 20:00:36
%%DocumentData: Clean7Bit
%%LanguageLevel: 2
%%EndComments
%%BeginProlog

It appears to me that running the eps output file through ps2epsi will
re-create a tight bounding box, perhaps it is sufficient for your
need.

Rather than wrestle with the postscript & ghostscript, I re-did this
on a pdf output device. It appears to me that the margin placement is
not affected by embedFonts.


pdf('lowess.pdf', onefile=FALSE, pointsize=18,
family="NimbusSan",height=6,width=6,paper="special")
plot(x,y)
lines(ml)
text (-1,1,"Really big writing")
dev.off()

I believe it is important to specify paper="special" here.

I wondered about your experience with par(mfcol---).  Lately, I've had
more luck printing out the smaller separate components and putting
them on the same LaTeX figure. That way, I have a little more control,
and the fonts in the figure captions are identical to my text, which I
like.


PJ
#
Paul Johnson wrote:
Paul,

Thank you very much.  Your pdf fix did the trick.

What is your favorite way of composing the multiple plots into a LaTeX 
figure?

ps2epsi resulted in a good bounding box but a huge graphics file.

Thanks,
Frank