Exporting PNG files from Plotly in R

十年热恋 提交于 2019-11-27 23:01:12

In the Plotly docs in CRAN I discovered the function plotly_IMAGE.

Here is a example:

set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]
p <- plot_ly(d, x = carat, y = price, text = paste("Clarity: ", clarity),
        mode = "markers", color = carat, size = carat)

plotly_IMAGE(p, width = 500, height = 500, format = "png", scale = 2,
             out_file = "~/desktop/test.png")

UPDATE

plotly_IMAGE works using Plotly server. A local solution is welcome.

There is a export function which allows you to save images without the need to connect to plotly servers. You can find it in the plotly package doc:

p <- plot_ly(...)
export(p, file = "image.png")

You can even change the file type of output by selecting the extension as .png, jpeg or .pdf.

You can also save the image in html file which allows you the plotly experience like zooming or showing annotations by using htmlwidgets::saveWidget:

p <- plot_ly(...)
htmlwidgets::saveWidget(p, file = "image.html")
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!