[英]R ggsave outputs different looking pdf and png
I have a strange problem using the ggsave function to save pdf and png figures. 使用ggsave函数保存pdf和png数字时,我遇到了一个奇怪的问题。 Apparently the resulting figures look somewhat different. 显然,得出的数字看起来有些不同。 Please see here: 请看这里:
(left png, right pdf) (左png,右pdf)
The pdf-file has the grid line drawn in black, while the png-file correctly displays the grid line in grey. pdf文件的网格线绘制为黑色,而png文件的网格线正确显示为灰色。 I have attached a minimal example 我附上了一个最小的例子
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)
Session info: 会话信息:
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS 10.14.2
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] cowplot_0.9.3 forcats_0.3.0 stringr_1.3.1 dplyr_0.7.6 purrr_0.2.5 readr_1.1.1 tidyr_0.8.1
[8] tibble_1.4.2 ggplot2_3.0.0 tidyverse_1.2.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.17 cellranger_1.1.0 pillar_1.3.0 compiler_3.5.1 plyr_1.8.4 bindr_0.1.1
[7] tools_3.5.1 jsonlite_1.5 lubridate_1.7.4 nlme_3.1-137 gtable_0.2.0 lattice_0.20-35
[13] pkgconfig_2.0.1 rlang_0.2.1.9000 cli_1.0.0 rstudioapi_0.7 yaml_2.1.19 haven_1.1.2
[19] bindrcpp_0.2.2 withr_2.1.2 xml2_1.2.0 httr_1.3.1 hms_0.4.2 grid_3.5.1
[25] tidyselect_0.2.4 glue_1.3.0 R6_2.2.2 fansi_0.2.3 readxl_1.1.0 modelr_0.1.2
[31] magrittr_1.5 backports_1.1.2 scales_0.5.0 rvest_0.3.2 assertthat_0.2.0 colorspace_1.3-2
[37] labeling_0.3 utf8_1.1.4 stringi_1.2.4 lazyeval_0.2.1 munsell_0.5.0 broom_0.5.0
[43] crayon_1.3.4
I have now found the issue. 我现在发现了问题。 By replacing theme_linedraw()
with theme_bw()
the PDF and PNG figures are identical. 通过替换theme_linedraw()
与theme_bw()
的PDF和PNG的数字是相同的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.