0

I am learning ggplot2 and try to use the ggsave() method to save my plot to a picture. I want my final graph to be 300 dpi, but no matter how I change the 'dpi=' value, what I finally got was only a graph with 72 Pixels/Inch, so what is the problem with my code?

ggsave(filename="./test4.jpg", units = "in", width =20, height = 10, dpi = 300, device='jpg')

I also tried the solution proposed by others before, I still got a graph of 72 dpi:

tiff("test.tiff", units="in", width=5, height=5, res=300)
# insert ggplot code
dev.off()
Z.Lin
  • 28,055
  • 6
  • 54
  • 94
Jiang Xu
  • 91
  • 1
  • 10
  • 1
    What do you mean with "increase the dimension of the graph" in the title? How did you determine the 72 Pixels/Inch? If you run the `ggsave` command with `dpi=300` and `dpi=72`, what are the size of the files generated (in kB)? – Alexlok Aug 24 '20 at 05:02
  • I mean the when I changed the resolution from 75 to 300 by setting res=75 to res=300 or by setting dpi=75 to dpi=300, What I expected to see is the change of resolution, but not the height and width. It turned out both methods produce picture with increased pixel sizes(or increased height and width), with resolultion still at 72 pixel per inch as I checked using Photoshop. – Jiang Xu Aug 24 '20 at 06:14
  • I just tried both these methods on a simple plot and when I opened it in photoshop it had the correct DPI. I cannot reproduce this problem. What version of ggplot are you using? What program are you using to open the files? – MrFlick Aug 24 '20 at 07:04

1 Answers1

0
ggsave(filename = "figure2.png",
       a,
       width = 2.14, height = 1.51, dpi = 300,units = "in",
       type = "cairo")
Martin Gal
  • 16,640
  • 5
  • 21
  • 39
zzw0034
  • 21
  • 2
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 09 '22 at 21:09