To elaborate on the other answers:
My understanding is that fig.width
and fig.height
don't work for leaflet
(or plotly
) because they are html objects, not 'true figures' as far as knitr
is concerned. leaflet
(and plotly
) do however respond to out.width
, which is why it works.
In case anyone ever has a similar situation to me:
I have a code chunk which conditionally includes either a leaflet
map (for html output), or 4x saved ggplot
.png images using knitr::include_graphics(p1, p2, p3, p4)
(for pdf output). In order to tile the 4 ggplot
objects in a 2x2 grid, I had to set out.width = '50%'
, but this also reduced the width of the leaflet
output.
The solution was to include leaflet(width = '100%')
in the code, and out.width = '50%'
in the chunk header. leaflet(width = '100%')
seems to override out.width = '50%'
, giving me either a full sized leaflet
in html outputs, or 50% width ggplot
figures.