问题
When I save a ggplot
figure -- regardless of whether I use ggsave()
or e.g. png()
-- the facet labels come out looking blurry. For example, the following code produces a facet label 'F' that looks like the picture below, with coloration on the outer pixels of the text raster.
ggplot(data.frame(x=1, y=1, f='F'), aes(x, y)) +
facet_grid(. ~ f)
ggsave('foo.png')
Thanks in advance for any advice!
PS -- As per @Brian's request, I'm updating this post to note that I'm using a Windows machine.
PPS -- I'm updating my post again, this time to clarify that I plan to insert the figure into Word. So as per suggestion #4 from this post that @Masoud pointed me to, I would like to use a pixel-based format (e.g. PNG) rather than a vector-based format (e.g. PDF).
回答1:
Try disabling antialiasing
default (quartz):
ggsave('foo.png', antialias="none")
:
回答2:
Try save as vector-based format like .eps
:
ggplot(data.frame(x=1, y=1, f='F'), aes(x, y)) +
facet_grid(. ~ f)
ggsave('foo.eps', device = 'eps')
Alternatively you can save the image as a .jpeg and increase the Dots Per Inch with option dpi.
ggplot(data.frame(x=1, y=1, f='F'), aes(x, y)) +
facet_grid(. ~ f)
ggsave('foo.jpeg', device = 'jpeg',dpi = 5000)
There are multiple higher quality formats, you can check the specifics by running ?ggsave
来源:https://stackoverflow.com/questions/45821115/ggplot2-blurry-facet-labels