我正在使用JRI从Java生成ggplot2图表。目前,我必须将图表写入磁盘。如何在不通过文件的情况下完成这个过程,即只在内存中渲染图表?
我尝试使用Cairo包将绘图输出到textConnection,但这需要“R Connections Patch”,经过一些谷歌搜索,发现这已经过时了。
我正在使用JRI从Java生成ggplot2图表。目前,我必须将图表写入磁盘。如何在不通过文件的情况下完成这个过程,即只在内存中渲染图表?
我尝试使用Cairo包将绘图输出到textConnection,但这需要“R Connections Patch”,经过一些谷歌搜索,发现这已经过时了。
主要来源于https://stat.ethz.ch/pipermail/r-devel/2010-August/058253.html
library(Cairo)
library(png)
library(ggplot2)
Cairo(file='/dev/null')
qplot(rnorm(5000)) # your plot
# hidden stuff in Cairo
i = Cairo:::.image(dev.cur())
r = Cairo:::.ptr.to.raw(i$ref, 0, i$width * i$height * 4)
dim(r) = c(4, i$width, i$height) # RGBA planes
# have to swap the red & blue components for some reason
r[c(1,3),,] = r[c(3,1),,]
# now use the png library
p = writePNG(r, raw()) # raw PNG bytes
[更新:JRI可以处理原始数据,只需使用REngine抽象而不是JRI即可。]
png(NULL)
不起作用。 - Hedgehogmagick
;还有其他的吗? - Bob