Ggplot2: save graphics as EPS with embedded font

The magazine wants me to submit the data as EPS files. Exporting them as an EPS file from R using ggplot2, and then opening the EPS file in Adobe Illustrator, he tells me that "the font was not found in the system."

How to solve this problem? Here is the syntax that I am currently using.

library(ggplot2) a <-c("Sad Mood", "Cognition", "Fatigue", "Interest Loss", "Slowed", "Self-blame", "Suicidal Ideation", "Early insomnia", "Appetite", "Late insomnia", "Agitated", "Weight", "Middle insomnia", "Hypersomnia", "Age", "Sex") b <-c(20.7,16.5,13.8,13.1,8.8,6.4,6.1,3.6,3.0,2.5,2.1,1.3,0.9,0.7,0.4,0.1) c <-c(17.90,13.64,11.36,10.72,6.99,4.60,4.68,2.38,2.09,1.65,1.35,0.76,0.47,0.24,0.15,0.03) #lower CI d <-c(23.47,19.27,16.28,15.74,10.64,8.20,7.95,5.07,4.21,3.63,2.99,2.22,1.59,1.62,0.95,0.31) #upper CI data <- data.frame(a,b,c,d) data1 <- transform(data, a = reorder(a, order(b, decreasing = FALSE))) data1$label <-sprintf("%.1f", data1$b) ggplot(data1, aes(x=as.factor(a), y=b, order=a))+ geom_bar(stat="identity",fill='#888888',colour='#888888') +theme_bw() +coord_flip() + ylab("Relative importance estimation in %") +xlab("") + geom_errorbar(aes(ymin=c, ymax=d), width=.3, size=.5)+ geom_text(aes(label=label), size=4.5, vjust=.4,hjust=-1.5)+ scale_y_continuous(limits = c(-0, 25))+ theme(axis.text.x = element_text(size = 13))+ theme(axis.text.y = element_text(size = 13))+ theme(axis.title.x = element_text(size = 14, vjust=-.2)) 
+4
source share
1 answer

There is an R package called extrafont that I used to solve this problem in the past. Here is the solution I used.

Basically, there is a font database that R will use, and a font database that postcript will use. Most of the time, you don’t have to do what I did above with lines 12-27, but if you have a font with a custom naming scheme, you will have to manually edit the font database R.

Your main problem will be that the font name (and font name) is the same in R and PS. You should be able to do this by installing extrafont (installing it for the first time creates a font database in R) and downloading the fonts with the correct device.

0
source

Source: https://habr.com/ru/post/1502475/


All Articles