[英]Create ggplot2 plot in memory?
我試圖在內存中捕獲ggplot2圖形創建的結果,將其發送到服務器。 誰有個好主意如何解決?
我的代碼看起來像這樣:
data(mtcars)
x <- ggplot(mtcars, aes(x=mpg, y=hp)) +
geom_point(shape=1)
print(x) # RStudio can capture the output, but I'm unable to do it.
ggsave(filename="a.jpg", plot=x) # not really a solution, need it not on disk, but as blob in memory.
你可以使用magick
包來做到這一點。
library(magick)
data(mtcars)
x <- ggplot(mtcars, aes(x=mpg, y=hp)) +
geom_point(shape=1)
fig <- image_graph(width = 400, height=400, res=96)
print(x)
dev.off()
figpng <- image_write(fig, path=NULL, format="png")
figpng
現在是你的情節的一個原始向量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.