Update:
When I used ggsave()
or pdf()
to save the figure, it works but with warning:
font family 'Times-Roman' not found, will use 'sans' instead
Actually, I have this font installed in my OS, and R studio can display it correctly. And output to bitmap files are well, such as PNG, TIFF. The problem only happen when outputting to PDF files. Maybe something goes wrong in my OS ENV.
Thank you for the help.
When I exported the figure to pdf by clicking the Export
button in R studio, I found that once the font family was set, the exported pdf file would only contain a portion of my figure.
Is it the bug or just somethings I am wrong?
Here are my code and result:
R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
Platform: x86_64-apple-darwin16.7.0 (64-bit)
library('ggplot2')
library('gridExtra')
x = c(1:30)
y1 = 1.3^x + 10
y2 = x
class = c(rep('A',14),'B',rep('A',14),'D')
df1 = data.frame(x=x,y=y1,class = class)
df2 = data.frame(x=x,y=y2,clas = class)
P1 <- ggplot(df1,aes(x=x,y=y1,fill=class)) + geom_bar(stat = "identity") +
theme(text = element_text(family = 'Times-Roman'))
P2 <- ggplot(df2,aes(x=x,y=y2,fill=class)) + geom_bar(stat = "identity") +
theme(text = element_text(family = 'Times-Roman'))
grid.arrange(P1,P2,ncol=2)
And I cannot get the whole figure after exporting