Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resulting png file does not reflect requested image width and height in inches #57

Closed
carolinarr opened this issue Nov 1, 2023 · 4 comments

Comments

@carolinarr
Copy link

carolinarr commented Nov 1, 2023

I've been exploring the camcorder package, and am puzzled by the fact that when I start gg_record with a certain size request, the resulting saved files do not match the size requested. For instance, my gg_record() statement looks like this:

library(ggplot2)
library(camcorder)

camcorder::gg_record(
    dir = 'path/to/my/folder',
    device = "png",
    scale = 1,
    width = 3.5,
    height = 2.5,
    units = "in",
    dpi = 300,
    bg = 'white',
)

# example plot
ggplot(d = ToothGrowth, aes(x = len)) +
  geom_histogram(bins = 10) 

When I open the file in the Preview application or InDesign, the size is width 14.58 inches and height 10.42 inches at 72 pixels/inch. Am I missing something?

@gkaramanis
Copy link
Collaborator

You’re not missing anything, the short answer is that it’s complicated!

Here’s a blog post that explains how dimensions and resolution work, I hope it’s helpful:

https://www.christophenicault.com/post/understand_size_dimension_ggplot2

@carolinarr
Copy link
Author

That blog post is extremely helpful–thank you so much for the link!

I guess I had the wrong impression here; I thought I was avoiding those issues when using camcorder() over ggsave(), but is camcorder() essentially using ggsave() each time it records?

@gkaramanis
Copy link
Collaborator

gkaramanis commented Nov 2, 2023

Nice to hear it helped! And you're correct, camcorder uses ggsave.
I'm not sure there is a way to avoid the issues, my understanding is that this is how images work in general... 🤷

@carolinarr
Copy link
Author

Ok thank you, great to confirm. Very much appreciate your responses!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants