问题描述
这可能是该问题的更一般版本(如何保存grgough图表为.png ).
This might be a more general version of this question (How to save ggrough chart as .png).
我正在使用RStudio.通常,我可以按常规方式(png()
,jpeg()
和ggsave()
保存我的图.
I am using RStudio. I can typically save my plots usual ways (png()
, jpeg()
, and ggsave()
.
但是,我遇到了在RStudio Viewer中渲染图的情况,但是上述保存命令不起作用.
However, I have encountered situations where the plot renders in the RStudio Viewer, but these aforementioned saving commands do not work.
以下是remiotic
页上的示例,该页面位于 https://timelyportfolio.github.io/remiotic/:
Here is an example taken from the remiotic
page at https://timelyportfolio.github.io/remiotic/:
library(remiotic)
remiotic(
# lines expected to be an array of arrays
# for now do it the really ugly way
# but should be able to fix this fairly easily
data = list(
list(
group = "A",
coordinates = lapply(0:10, function(x) list(x=x, y=runif(1)))
)
),
frame = "XYFrame",
props = list(
shape = "lines",
xAccessor = "x",
yAccessor = "y",
xExtent = c(0, 10),
yExtent = c(0, 1),
lineStyle = list(stroke = "#629"),
margin = list(
top = 20,
right = 40,
bottom = 50,
left = 50
),
axes = list(
list(orient = "left"),
list(orient = "bottom")
)
),
width = "100%"
)
我尝试将jpeg("file")
,png("file")
和pdf("file")
放在此代码之前,并将dev.off()
放在之后.前两个不创建文件,第三个不创建文件,但是由于它没有将绘图保存到其中,因此我无法打开该文件.我有一台Mac;如果我将x11()
放在前面,它将打开新窗口,但会在RStudio Viewer中渲染图.
I have tried putting jpeg("file")
, png("file")
, and pdf("file")
before this code and dev.off()
after. The first two do not create a file and the third does, but I can't open the file as it didn't save the plot to it. I have a Mac; if I put x11()
in front, it opens the new window, but renders the plot in the RStudio Viewer.
如何使用代码(而不是RStudio的导出按钮)保存这样的图形?
How can I save a plot like this using code (and not RStudio's export button)?
推荐答案
rg <- remiotic(...)
htmlwidgets::saveWidget(rg, "remplot.html")
或者Webshot软件包将允许捕获为png.
Or Webshot package would allow for capture as png.
library(webshot)
webshot("remplot.html", "remplot.png")
这篇关于如何保存通常方法无法保存的图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!