1

I am trying to get figures ready for publication, where the journal requires the figures to be a certain width and height and the font size to be 10.

This is my basic structure:

cairo_ps(file = "plot.eps", width = 6.85, height = 9.213)
dotplot(...)
dev.off()

I've tried to force the font size using trellis.par.set, trellis.device and setting it with pointsize in the device itself, but no luck. I can't get to change the font size to be anything than it defaults to. Any ideas?

Gimelist
  • 791
  • 1
  • 10
  • 25
  • Why don't you set the font size using Cairo? It also hase a pointsize argument. – SimonG Aug 30 '14 at 12:12
  • I did. Read my question carefully. – Gimelist Aug 30 '14 at 13:24
  • Could you provide a reproducable data example so to check and see what you already did? With a minimal example, I can reproduce this behavior, meaning that lattice graphics are not affected by changes if `pointsize` made in the graphics device. – SimonG Aug 30 '14 at 14:39

1 Answers1

1

You could use Cairo instead. This solution can, however, yield some unexpected results as it seems, for example when changing the dpi argument when calling Cairo.

There seems to be some coding problems involved. For example, I have to re-run the code after changing the font size for changes to take effect. Be warned! You might have to tweak it a bit to get the font size you want.

Contrary to the built-in graphics devices, however, this seems to react to changes made by trellis.par.set. Here is a example with PNG, the same works for me with PDF:

dat <- data.frame(a=1:3, b=1:3)

Cairo(file = "plot.png", type="png", units="in", width = 6, height = 3, dpi=100)
xyplot(b~a, dat) 
trellis.par.set("fontsize", list(text=12, points=8)) 
dev.off()

enter image description here

Compare to:

Cairo(file = "plot.png", type="png", units="in", width = 6, height = 3, dpi=100)
xyplot(b~a, dat) 
trellis.par.set("fontsize", list(text=18, points=8)) 
dev.off()

enter image description here

SimonG
  • 4,701
  • 3
  • 20
  • 31
  • Is `Cairo()` from the similarly named package? – Gimelist Aug 30 '14 at 19:10
  • 1
    Yes, the package and the "generic" function are both named `Cairo`. There are also output-specific devices `CairoPDF()` etc. but `Cairo()` is the generic interface. – SimonG Aug 30 '14 at 19:35
  • Works! Seems like my problem was with `trellis.par.set`. If you put it before the plotting command, you don't have to re-run it twice. Once I got that right, `cairo_ps()` did the work. It does seem however that `Cairo()` is a bit more convenient than `cairo_ps()`. – Gimelist Aug 30 '14 at 19:58
  • Ha, did NOT think of that. Glad it could still help a bit! – SimonG Aug 30 '14 at 20:05
  • One last thing, for some reason `Cairo()` does not work that well and occasionally spits out errors. On the other hand, `CairoPS()` works just fine! – Gimelist Aug 30 '14 at 20:07