Saving plotly plot to a PDF in R - how to scale to 100% width

40 Views Asked by At

I am trying to save a plotly chart to a PDF so that the chart is 100% the height and width of the PDF. Sample code below.

The only way I can scale the chart to 100% width of the PDF is by using the zoom argument of webshot() - via trial and error. A value of 0.6 seems to work well.

Is there a way to control the size of the chart so that webshot() creates a PDF that accurately reflects the size of the plotly chart?

library(plotly)
library(htmlwidgets)
library(webshot)

fig <- plot_ly(economics, x = ~pop, type = 'histogram')
saveWidget(fig, file="temp.html")

webshot("temp.html", "temp.pdf")                   # does not fill the page
webshot("temp.html", "temp_zoom.pdf", zoom = 0.6)  # does fill the page
0

There are 0 best solutions below