fontcm icon indicating copy to clipboard operation
fontcm copied to clipboard

Cannot reproduce README example for ggplot2

Open sctyner opened this issue 7 years ago • 1 comments

Hi Winston, I cannot recreate the ggplot2 example from the README. The base graphics plot example works just fine, but the ggplot2 one produces identical pdfs before and after the font change. This is the message I get:

Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
  polygon edge not found
In addition: Warning messages:
1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "CM Roman"

with the warning message 1 repeated several times.

However, when I try your example here, it works just fine when I switch the family to "CM Roman" and use ggsave. I still get the same warnings as above, and the plot doesn't render in RStudio, but the pdf output looks good (attached).

Any idea what might be happening?

Thanks, Sam font_ggplot.pdf

sctyner avatar Sep 14 '17 17:09 sctyner

Hello @sctyner,

I just faced the same issue and I tried to put the equation into the example you attached. And it works.

 library(ggplot2)
 p <- ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() +
      ggtitle("Fuel Efficiency of 32 Cars") +
      xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
      theme(text=element_text(size=16, family="Pagul")) + 
      annotate("text", x=3, y=3, parse=TRUE, family="CM Roman", label=eq) +
      theme(text         = element_text(size=16, family="CM Roman"),
      axis.title.x = element_text(face="italic"),
      axis.title.y = element_text(face="bold"))

      ggsave("font_ggplot.pdf", plot=p,  width=4, height=4)
      embed_fonts("font_ggplot.pdf")

I did not go into the details of this but maybe the issue is related to the quick version of ggplot2 (qplot). At least by working with ggplot2 you can be sure that you will get the results you want.

If anyone else has more details, please let us know :smile:

Best regards, Agustín

Fustincho avatar Apr 04 '18 13:04 Fustincho