Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot embedded fonts in pdf

Tags:

I have been using the following guide to export plots made with ggplotto pdf: plot fonts guide

It raises the issue at the bottom of the post of some fonts not appearing as they should, which happens in my example below. The text in font Bauhaus 93 appears correctly whilst the text in Calibri is displayed incorrectly.

Has anyone found a way to resolve this issue?

library(ggplot2)
library(plyr)
library(grid)
library(gridExtra)
library(extrafont)

data1<-as.data.frame(1:5)
data1[,2]<-as.data.frame(c(1,3,5,7,9))
data1[,3]<-as.data.frame(c(2,4,6,8,10))
colnames(data1)<-c("x","y1","y2")

ggplot(data1, aes(x=x)) + 
  geom_line(aes(y = y1, colour = "Taux selon DEF"), size=0.61, colour="black") +  
  geom_line(aes(y = y2, colour = "Taux selon EC"), size=0.61, colour="black", linetype="dashed") + 
  xlab("X axis lab") + ylab("Y axis lab)") +
  annotate("text", x=1, y=4, label="Some text here", size=2, family="Bauhaus 93") +
  annotate("text", x=4, y=1, label="More text here", size=2, family="Calibri") +
  theme_bw() + theme(legend.title = element_blank(),
                     legend.key = element_rect(fill=NA),
                     panel.border = element_blank(), 
                     axis.line = element_line(colour="black", size=0.25),
                     axis.ticks = element_line(size=0.25),
                     panel.grid.major = element_line(colour = "grey80", size=0.25),
                     panel.grid.minor = element_line(colour = "grey80", size=0.25),
                     axis.text.x = element_text(size=5.5 , lineheight=0.9, hjust=0.5, family="Bauhaus 93"),
                     axis.text.y = element_text(size=5.5 , lineheight=0.9, vjust=0.5, family="Calibri"),
                     axis.title.y = element_text(size=6.1, angle=0, vjust=0.975, face="bold", family="Calibri"),
                     axis.title.x = element_text(size=6.1, angle=0, vjust=-0.20, face="bold", family="Calibri")) +
  scale_x_continuous(expand = c(0, 0), limits=c(0,5)) + 
  scale_y_continuous(expand = c(0, 0), limits=c(0,10)) +
  ggtitle("Title") +
  ggsave("Test.pdf", width=7, height=5)
Sys.setenv(R_GSCMD = "C:/Program Files (x86)/PDF24/gs/bin/gswin32.exe")
embed_fonts("Test.pdf")
like image 777
user2568648 Avatar asked Dec 18 '14 08:12

user2568648


People also ask

How do I add an embedded font to a PDF?

To embed the fonts that are not already embedded, go to File > Print. Bring up the Adobe PDF settings and properties, then Adobe PDF settings. Embed your font. Edit the default settings and navigate to Font, click the Embed all fonts option.

How do I fix PDF fonts not embedded in a PDF?

In Acrobat Pro, Tools > Print Production > Preflight > expand “PDF Fixups” > select “Embed Fonts” > click “Analyze and fix”.

Why are fonts not embedded in PDF?

When a font cannot be embedded because of the font vendor's settings, and someone that opens or prints the PDF does not have access to the original font, a Multiple Master typeface is temporarily substituted–AdobeSerifMM for a missing serif font, and AdobeSansMM for a missing sans serif font.

What is embedded subset font in PDF?

If a subset of a font is embedded, this means that only the characters used in that particular document are embedded. This is acceptable for a thesis or dissertation, because these documents will not be edited in their pdf form.


1 Answers

Try adding device=cairo_pdf to the ggsave() call. This appears to solve the problem for me. This way, it's no longer necessary to use embed_fonts().

See mgaudet's comment here: https://github.com/wch/extrafont/issues/8

like image 76
Nicholas Avatar answered Sep 20 '22 15:09

Nicholas