1

I'm trying to export a figure with dimensions 90x150 mm with 300 dpi using the ggsave() and Cairo(). The problem is that even though I correctly specified the figure dimensions on the code, they ended up far bigger then expected (281x468 mm). Here's the code I've been using:

x <- 1:10; y = x*x
plot = qplot(x, y, geom=c("point", "line"))

#ggsave
ggsave(plot, filename = "test.png", 
       width = 90, height = 150, dpi = 300, units = "mm", type = "cairo")

#Cairo
Cairo(90, 150, file="test2.png", type="png", bg="white", res = 300, units = "mm")
plot
dev.off()
Gabriel Lucas
  • 170
  • 1
  • 2
  • 14
  • 1
    If you remove `units = "mm"` from Cairo it plots the correct size (90 X 150) – jared_mamrot Jan 20 '21 at 01:32
  • It actually plots the 90x150 size in pixels, since it's the Cairo's default output. But thank you, your comment made me realise why it doens't work. Basically the figure size is also affected by the resolution, even if I choose a "metric" system as output. Thats why 90 mm got turned into 280 mm at 300 dpi, since 100 dpi is the default. – Gabriel Lucas Jan 20 '21 at 02:15

1 Answers1

1

Just figured out that Cairo() and ggsave() size output is affected by the image resolution, even if you choose a "metric" dimension as output.

So basically, if you want a 90x150 figure at 300 dpi, you have to divide by 3 this dimensions (since 300 dpi is 3x the default resolution, 100dpi). Your setup then will be 30x50.

Gabriel Lucas
  • 170
  • 1
  • 2
  • 14