I am trying to get rmarkdown to output pdf for each of individual id(row). I have Chinese font in the ggplot().
The rmarkdown content looks like this:
library(ggplot2)
chinesetext=theme(text=element_text(family='STXihei')) # add support on chinese in ggplot
ggplot(subgroup)+
geom_line(data=subgroup,aes(y=mpg,x=wt,color='c1'))+geom_point(aes(y=mpg,x=wt))+
geom_line(data=subgroup,aes(y=cyl,x=wt,color='c2'))+geom_point(aes(y=cyl,x=wt))+
scale_color_manual(values=c('c1'='red','c2'='orange'),labels=c('xx','yy'))+
labs(x='t',y='score')+
chinesetext
The R script looks like this:
library(rmarkdown)
for (id in unique(mtcars$carb)){
subgroup <- mtcars[mtcars$carb == id,]
render("/Users/mtcars.Rmd",output_format='pdf_document',output_file = paste0('report.', id, '.pdf'))
}
I got the error:
Quitting from lines 10-25 (mtcars.Rmd)
Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
invalid font type
In addition: There were 50 or more warnings (use warnings() to see the first 50)
I have tried many solutions people discussed online without any luck. I know this is a font issue, as the error indicated. Has anyone experienced it and worked it out? I can get the code run to output HTML docs, but I really need PDF. Thank you very much.