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

ggsave() produces aliased png files on Windows #4040

Closed
thomas-neitmann opened this issue Jun 1, 2020 · 2 comments
Closed

ggsave() produces aliased png files on Windows #4040

thomas-neitmann opened this issue Jun 1, 2020 · 2 comments

Comments

@thomas-neitmann
Copy link

When using ggsave() to save a plot as png on Windows the resulting image is quite aliased (zoom in to see the ragged line).

library(ggplot2)
data(gapminder, package = "gapminder")
china <- gapminder[gapminder$country == "China", ]

ggplot(china, aes(year, lifeExp)) + geom_line()
ggsave("test.png")

test

This is a known issue of the png() graphics device on Windows. To mitigate this one has to use cairo and set the antialias argument like so.

ggsave("test2.png", type = "cairo-png", antialias = "subpixel")

test2

This is easy enough if you know this trick. I'd suggest to automatically set type = 'cairo-png' and antialias = 'subpixel' on Windows if these arguments have not been explicitly set. I've recently implemented something along those line in the {hexSticker} package which uses ggsave(). Have a look here.

I'd be happy to create a pull request.

@yutannihilation
Copy link
Member

Thanks. I agree to change the default, but we tend to recommend ragg package for high quality plots.

@thomasp85
Copy link
Member

I'm closing this for now, since we need to have a broader discussion about whether to force certain devices (ragg) on the user

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

3 participants