Exporting PNG files from Plotly in R

前端 未结 4 1045
自闭症患者
自闭症患者 2020-12-06 05:17

How can I export a Plotly chart as a image from R using code? (Not using the export button on the chart).

For example, this code from the Plotly site, create this ch

4条回答
  •  天命终不由人
    2020-12-06 06:03

    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.

提交回复
热议问题