ggplot2: blurry facet labels

旧时模样 提交于 2021-02-19 02:34:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!