将散点图从PDF导入R
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将散点图从PDF导入R相关的知识,希望对你有一定的参考价值。
我正在尝试从PDF导入散点图。该图最初是在R中创建的。当我导入PDF时,我无法看到散点。不确定我做错了什么?线条图似乎工作正常。
演示问题的玩具示例:
pdf(file = "./temp.pdf", height = 5, width = 5)
plot(mtcars$mpg, mtcars$cyl, type = "p")
dev.off()
file.show("temp.pdf")
# same issue with ggplot
# pdf(file = "./temp.pdf", height = 5, width = 5)
# ggplot(data = mtcars, mapping = aes(x = mpg, y = cyl)) +
# geom_point()
# dev.off()
p0 <- magick::image_read_pdf('./temp.pdf')
p0
p1 <- pdftools::pdf_render_page('./temp.pdf')
png::writePNG(p1, "temp.png")
file.show("temp.png")
> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.6.0 magrittr_1.5 magick_2.0 tools_3.6.0 Rcpp_1.0.1
[6] pdftools_2.2 qpdf_1.1 png_0.1-7 askpass_1.1
答案
对于未来遇到这种情况的人来说,useDingbats = FALSE
函数中的pdf()
为我做了诀窍,即
pdf(file = "./temp.pdf", height = 5, width = 5, useDingbats = FALSE)
以上是关于将散点图从PDF导入R的主要内容,如果未能解决你的问题,请参考以下文章