Saving plots in R
2
2
Entering edit mode
6.8 years ago
KVC_bioinfo ▴ 600

Hello All,

I am trying to save plot which I generated using ggplot in R. I saved with .jpeg, .pdf, .png formats. But none of them look good when I try to resize it for putting it on a presentation slide. Could someone suggest what is the best format to save those plots in order to look good on slides?

TIA.

ggplot R • 30k views
ADD COMMENT
6
Entering edit mode

Alternatively, you could try setting the resolution and dimensions when saving in e.g. jpeg:

jpeg(
    filename="yourfilename.jpeg",
    width=8,
    height=8,
    units="in",
    res=500)
ADD REPLY
1
Entering edit mode

We also like to use EPS because we edit our figures in Adobe Illustrator and it's annoying to work with SVG files in Illustrator.

ADD REPLY
1
Entering edit mode

Oh, this is also a great solution. I had no idea about the svg to emf conversion and that emf was an Office-preferred format.

ADD REPLY
0
Entering edit mode

Perfect. Thank you so much!

ADD REPLY
2
Entering edit mode

Just a comment: For publication-ready images, you should always generate via vector-based transformations (SVG, PDF, etc) and not pixel-based (BMP, JPEG, TIFF, PNG, etc). The top journals will flat out reject pixelated images because they cannot easily be manipulated and look terrible when one zooms in.

I always default to using PDF.

ADD REPLY
4
Entering edit mode
6.8 years ago

How are you saving the plots? If you're manually saving them (say from Rstudio), the resolution is pretty bad (like 72 dpi or something by default).

The easiest way I've found to save plots with good resolution is as follows:

pdf(file = "FileName.pdf", width = 8, height = 11) # defaults to 7 x 7 inches
plot(x, y)
dev.off()

postscript("FileName.eps", width = 12, height = 17, horizontal = FALSE, 
           onefile = FALSE)
plot()
dev.off()

tiff("FileName.tiff", height = 30, width = 20, units='cm 
     compression = "lzw", res = 300)
plot()
dev.off()

The pdf and postscript option yields files that you can additionally edit in Illustrator, whereas tiff gives a high-res image file that's much better than typical jpegs or png files. These commands won't show the plots, but will save them directly to the file specified.

ADD COMMENT
2
Entering edit mode
3.1 years ago
Eijy Nagai ▴ 90

I'm late for the party, but I use and suggest another approach.

ggsave("you_plot_name.pdf", width = 12, height = 6)

This command will plot the last plot you made. As I am using Jupyter notebook/lab it's very handy when you just find the perfect combination of width and heigh with the command options(repr.plot.width = 12, repr.plot.height = 6)

I used to use the pdf() + dev.off() set, but the thing is that you save running time with the notebooks using this single-line approach.

ADD COMMENT
0
Entering edit mode

But if your plots have all same size, then the pdf() + dev.off() will work best as you can concatenate them into one file.

ADD REPLY

Login before adding your answer.

Traffic: 2001 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6