我想将以下绘图的输出捕获到包含位图的变量中,在 R 中:
require(stats)
plot(sin, -pi, 2*pi) # see ?plot.function
这会在硬盘上保存一个位图文件:
bmp("spam.bmp")
plot(sin, -pi, 2*pi)
dev.off()
谷歌搜索R save bitmap
给你这个答案。
包解决magick
方案:
img <- magick::image_graph(width = 256, height = 256, res = 96, pointsize = 1, clip = FALSE)
plot(sin, -pi, 2*pi)
dev.off()
img
#> format width height colorspace matte filesize density
#> 1 PNG 256 256 sRGB TRUE 0 +72x+72
arr <- magick::image_data(img)
str(arr)
#> num [1:256, 1:256, 1:4] 1 1 1 1 1 1 1 1 1 1 ...