R ggsave输出不同外观的pdf和png

时间:2019-01-02 14:02:07

标签: r ggplot2

使用ggsave函数保存pdf和png图形时,我遇到了一个奇怪的问题。显然,得出的数字看起来有些不同。请在此处查看:

(左png,右pdf) enter image description here

pdf文件的网格线绘制为黑色,而png文件的网格线正确显示为灰色。我附了一个最小的例子

struct Complex* complexArray = malloc((length + 1) * sizeof(struct Complex));

会话信息:

library('tidyverse')
set.seed(1)
df <- tibble(x = rnorm(1000))
p <- df %>% ggplot(aes(x)) +
  geom_histogram(bins = 20, fill = 'grey85', col = 'black', alpha = .4) +
  theme_linedraw()
p

ggsave( 'test.pdf', p, device = 'pdf', width = 5, height = 5)
ggsave('test.png',p, device = 'png',  width = 5, height = 5)

1 个答案:

答案 0 :(得分:1)

我现在发现了问题。通过将theme_linedraw()替换为theme_bw(),PDF和PNG数字是相同的。

相关问题