I'm trying to include a plotly chart into a Latex document with knitr. Since knitr includes the webshot package this works well. But if I want to resize my figure for the latex output, the figure environment gets bigger but the plotly chart is not scalled to the manually set figure width and height.
Specifing the webshot options like recommend here, did not work neither. Scaling a ggplot chart works well, but how can I get the same results for the plotly chart?
\documentclass{article}
\usepackage{cleveref}
<<setup, echo=FALSE, message = FALSE, warning = FALSE>>=
library(ggplot2)
library(plotly)
@
%Preamble
\title{GGplot vs. Plotly }
\author{authors}
\date{2016}
\begin{document}
\maketitle
\section{Comparison ggplot with plotly}
This document illustrate the difference between ggplot and plotly. The chart in (\Cref{fig:ggplot}) is well placed in the document, but the chart in (\Cref{fig:plotly}) is neither scalled to the figure width, nor positioned next to the label.
<<ggplot, fig.lp="fig:", fig.cap = 'This is rendered with ggplot()', echo=FALSE, fig.width = 10, fig.height = 6>>=
ggplot(midwest, aes(x = state, y = percollege, colour = state)) + geom_boxplot()
@
<<plotly, fig.lp="fig:", fig.cap = 'This is rendered with plotly()', echo=FALSE, fig.width = 10, fig.height = 6, screenshot.opts = list(delay = 2, cliprect = 'viewport')>>=
plot_ly(midwest, x = ~state, y = ~percollege, color = ~state, type = "box")
@
\end{document}
I saw that the graphic file figure/plotly-1.pdf (generated by knitr/webshot, and then loaded into latex) has two pages and the plotly object is somewhere in the upper left corner. I guess the margins included in the webshot figure are in fact the problem.
R 3.2.3 knitr 1.14 ggplot2 2.1.0 plotly 4.5.2