0

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

here is my result

Hermione
  • 11
  • 3
  • 1
    Your code works fine on my machine: `RStudio Version 1.2.5001` and `R version 3.6.1 (2019-07-05)`. – Zhiqiang Wang Oct 16 '19 at 04:07
  • 1
    Better use `ggsave()` so you don't have to do it manually. Example here https://stackoverflow.com/a/51906008/786542 – Tung Oct 16 '19 at 04:24

0 Answers0