0

when I make graphics in R, I use specific settings for aesthetics. Saving graphics as PDF maintains the quality of almost all elements. But when I copy the graphics, as a metafile to the clipboard to use them in .doc or .docx documents, I lose all quality, even when I save the document as PDF

library (ggplot2)

Source <- c(rep("Water", 12), rep("Oil", 12))
Range <- rep((c(rep("First", 4), rep("Second", 8))),2)
Xaxis <- c(0,1,2,5,0,1,2,5,10,20,30,40,
           0,1,2,5,0,1,2,5,10,20,30,40)
Yaxis <- c(0,1,2,5,0,1,2,5,10,20,30,40,
           0,1,2,5,0,1,2,5,10,20,30,40)

DF <- data.frame(Source, Range, Xaxis, Yaxis)

#plot
p <- ggplot(data = DF, aes(x = Xaxis, y = Yaxis)) +
  geom_smooth(method = "lm") +
  geom_point() +
  facet_grid(Range~Source,
             scales = "free")

#Aesthetic settings
theme_set(
  theme_bw() +
    theme(line = element_line(colour = 1, size = 0.125),
          rect = element_rect(colour = 1, size = 0.125),
          text = element_text(colour = 1, size = 8),
          axis.title = element_text(face="bold", size = 8),
          axis.text = element_text(colour = 1, size = 8),
          axis.ticks = element_line(colour = 1),
          legend.title = element_text(face="bold", size = 8),
          legend.title.align = 0.5,
          legend.background = element_rect(fill = NA),
          legend.box.background = element_rect(colour = 1),
          panel.border = element_rect(colour = 1),
          strip.background = element_rect(colour = 1),
          strip.text = element_text(colour = 1, size = 8))
)

update_geom_defaults("point", list(size = 0.8))
update_geom_defaults("smooth", list(size = 0.125))
update_geom_defaults("linerange", list(size = 0.125))

p

In the R studio internal viewer

enter image description here

Plot saved as PDF (desired quality) enter image description here

Plot copied to the clipboard as a metafile and pasted into a .docx document

Crooked lines, different point sizes than expected. These aesthetic defects are maintained even when saving the .docx document as PDF enter image description here

Daniel Valencia C.
  • 2,159
  • 2
  • 19
  • 38
  • 2
    Is copy/pasting from RStudio a must? What about saving as a nice high quality raster graphic like a PNG and inserting or copy/pasting that file into Word? – Gregor Thomas Mar 23 '21 at 13:57
  • 1
    `ggsave()` and Insert Picture. – TTS Mar 23 '21 at 14:01
  • 1
    In short: don't do that. As other's mentioned, it is much more preferred to save as a picture with `ggsave()` and insert into your document - save as PNG and then you can just work with it as a picture file. You can also use a Markdown file to generate a Word document directly with the graphics embedded. – chemdork123 Mar 23 '21 at 14:48
  • You might also look into the `officer` and `rvg` packages, which allow you to save vector graphics directly into a [new] word doc. – Jon Spring Mar 23 '21 at 15:51

0 Answers0