6

I am using R on a macbook.

This code:

postscript("plot.eps")
ggplot(SomeData, aes (x=Cue, y=var1, group=var2, color=var2, shape=var2)) + 
  geom_line(size=0.5) + 
  geom_point(size = 3) +
  geom_errorbar(aes(ymin=Var1-ci, ymax=Var1+ci), width=0.15, size=0.5) +  
  xlab("Var1") + ylab("Var2")+ 
  coord_cartesian(ylim=c(600, 675)) + 
  theme(axis.text = element_text(colour = "black")) + 
  scale_colour_manual(values=darkcols) + 
  theme(text = element_text(size=16, family="Times New Roman")) + 
  theme(legend.position="bottom")
dev.off()

returns this error:

Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
family 'Times New Roman' not included in postscript() device

Font family is defined on the plot. Tried defining it with postscript(family="Times") and postscript(family="Times New Roman") with no success

Tried font_import() / loadfonts(), but doing that generates more errors (Plot wont even show up on QUARTZ after doing this)

Checked the disabled fonts in the font folder, Times New Roman is enabled.

Checked the fonts available in R with names(postscriptFonts()) and it is there.

Like I said, plot looks perfectly in Quartz, but saving it as .eps with postscript generates the mentioned error and a blank file.

Any ideas on how to solve?

Undo
  • 25,519
  • 37
  • 106
  • 129

2 Answers2

4

You could also try using the Cairo package, which in my experience works better with different fonts.

library(Cairo)
cairo_ps("test.eps", family = "Times")
plot(rnorm(100))
dev.off()
maccruiskeen
  • 2,748
  • 2
  • 13
  • 23
2

this seems to work (for Times). So I think you just need to add family="Times" to your postscript() function.

p <- ggplot(mtcars, aes (x=cyl, y=disp)) + 
  geom_point(size = 3) +
  theme(text = element_text(size=16, family="Times")) + 
  theme(legend.position="bottom")

postscript("plot.eps", family="Times")
p
dev.off()
MLavoie
  • 9,671
  • 41
  • 36
  • 56