r - 如何将 Highcharter 图保存为本地磁盘上的图像?

标签 r r-highcharter

hc %>% 
  hc_add_series(name = "London", data = citytemp$london, type = "area") %>% 
  hc_rm_series(name = "New York")

我想将 hc 导出为 png 或 jpg。这可以通过选择导出 - 另存为图像来完成,但我想通过代码来完成,因为我有多个要导出的图。我已尝试以下操作,但它返回了空白图像:

png('hc.png', width = 800,height = 400)
print(hc)
dev.off()

最佳答案

这应该可以通过 webshot 包实现(请参阅此处的问题:https://github.com/jbkunst/highcharter/issues/186)

library(webshot)
library(highcharter)
library(plyr)

data("citytemp")

plot <- highchart() %>% 
  hc_add_series(name = "London", data = citytemp$london, type = "area") %>% 
  hc_rm_series(name = "New York")

htmlwidgets::saveWidget(widget = plot, file = "~/plot.html")
setwd("~")
webshot::webshot(url = "plot.html", 
                 file = "plot.png")

关于r - 如何将 Highcharter 图保存为本地磁盘上的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59885304/

相关文章:

r - 有没有办法根据 hcboxplot() 中的组对箱线图进行着色?

r - 插入符 - 使用 train()、predict() 和 resamples() 的不同结果

r - 仅合并来自 R 中不同数据帧的一两列

r - R 中的标注文本

r - 如何针对大型数据表优化 R 中的 for 循环

r - 使用 choroplethr 包时修复了 Shiny 中 choropleth 的范围

javascript - Highcharts:根据悬停在标记上淡化 plotLines

r - Highcharter 不同系列的数据标签

javascript - Highcharter 弃用函数的输出与建议的不同

r - highcharts 中的分面函数