-5

我想将以下绘图的输出捕获到包含位图的变量中,在 R 中:

require(stats)
plot(sin, -pi, 2*pi) # see ?plot.function

在此处输入图像描述

4

2 回答 2

5

这会在硬盘上保存一个位图文件:

bmp("spam.bmp")
plot(sin, -pi, 2*pi)    
dev.off()

谷歌搜索R save bitmap给你这个答案。

于 2013-01-17T20:03:12.050 回答
0

包解决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 ...
于 2019-03-11T04:25:02.173 回答