I'd like to capture the output of the following plot to a variable containing a bitmap, in R:
require(stats)
plot(sin, -pi, 2*pi) # see ?plot.function
I'd like to capture the output of the following plot to a variable containing a bitmap, in R:
require(stats)
plot(sin, -pi, 2*pi) # see ?plot.function
This saves a bitmap file on the harddrive:
bmp("spam.bmp")
plot(sin, -pi, 2*pi)
dev.off()
Googling R save bitmap
get's you this answer.
Solution with magick
package:
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 ...