% hc_rm_series(na-6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 06:59:37 26 4
gpt4 key购买 nike

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/64355084/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com