简体   繁体   English

放大 R 中的 dyGraphs 并将图像另存为 png

[英]Zoom In dyGraphs in R and save image as png

I want to zoom in the dygraphs and save the image as png.我想放大dygraphs并将图像保存为png。 I have plot the graph using dygraph library and saved it as png but it is not zoomed in version.我已经使用 dygraph 库绘制了图形并将其保存为 png,但它没有放大版本。

library("webshot")
library("htmlwidgets")
lungDeaths <- cbind(ldeaths, mdeaths, fdeaths)
dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
  dyHighlight(highlightCircleSize = 5, 
              highlightSeriesBackgroundAlpha = 0.2,
              hideOnMouseOut = FALSE)

saveWidget(ab, "/path/", selfcontained = TRUE, libdir = NULL)

basePng <- paste("images",paste(file,".png"), sep='/')
webshot::webshot("/path/",file=basePng)

在此处输入图片说明

But I want plot as below(zoomed in):但我想要如下图(放大):

在此处输入图片说明

I want to plot zoomed in dygraph for more than 1000 files.我想为 1000 多个文件绘制放大的 dygraph。 Could anyone help me on this?有人可以帮我吗?

I hope this answer could help anyone,我希望这个答案可以帮助任何人,

I use dyRangeSelector() to "zoom" on the graph, then webshot to save it.我使用dyRangeSelector()在图形上“缩放”,然后使用webshot来保存它。

library(webshot)
library(htmlwidgets)
library(dygraphs)

# webshot::install_phantomjs()

lungDeaths <- cbind(ldeaths, mdeaths, fdeaths)
dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
        dyRangeSelector( dateWindow = c("1974-03-1","1974-06-10")) %>%
        dyHighlight(highlightCircleSize = 5, 
              highlightSeriesBackgroundAlpha = 0.2,
              hideOnMouseOut = FALSE)

saveWidget(ab,file ="ab.html", selfcontained = TRUE, libdir = NULL)

webshot(url = "ab.html",file="ab.png")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM