ggplot2: ggsave report “family 'Arial' not included in postscript() device”

Summary: ggsave() report "family 'Arial' not included in postscript() device"

Description: I loaded the extrafont package into R and it works pretty fine almost to the very end. I could print my plot, named p in the script. But when I tried to save the plot as eps file, the error appeared.

library(ggplot2)
library(tidyr)
library(ggpubr)
library(readxl)
library(extrafont)
loadfonts(device = "postscript")
loadfonts(device="win")
##font_import()

h1 <- read_excel("C:/Users/Administrator/Desktop/h1.xlsx")

p<-ggplot(h1,aes(x=status,y=index, group=participants))
#draw the dots
p<-p+geom_line(size=0.8)
#draw the lines
p<-p+geom_point(size=1)
#reverse the X order
p<-p+scale_x_discrete(limits=rev)
#delete labels on X-axis
p<-p+xlab(NULL)
#add labels on Y-axis
p<-p+ylab("Identified Index (events/hour)")
#delete the background color
p<-p+theme(panel.background=element_blank(),panel.grid=element_blank())
#change the properties of lines of x and y axis
p<-p+theme(axis.line.y =element_line(size=1.5,lineend="square"))
p<-p+theme(axis.line.x =element_line(size=1.5,lineend="square"))
#change the font of the y-axis label
p<-p+theme(axis.title.y=element_text(size=6, face=(1),family="Arial"))
#change the tick labels of both axis
p<-p+theme(axis.text=element_text(size=9, face=(1),color="black", family="Arial"))
#change the tick mark of both axis
p<-p+theme(axis.ticks=element_line(size=1,color="black"), axis.ticks.length = unit(5,"point"))
#change the limits and interval of y axis
p<-p+scale_y_continuous(limits=c(0,18),breaks=seq(0,18,by=2))
#add some margins to the plot
p<-p+theme(plot.margin=margin(t=50,r=10,b=20,l=20,"point"))
print(p)
##until here everything works fine
ggsave("test.eps",units="cm",plot=p,width=17.7,height=9.9)

Current Output:

Error in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)) : family 'Arial' not included in postscript() device

R Version: 4.0.3

Operating System: WIN 10

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.