I use the knitr::opts_chunk$set(fig.align = "center")
at the beginning of the rmarkdown document to set the alignment of figures. When I output HTML files, the static figures are aligned to the center, but the HTML widgets, such as outputs from leaflet()
and ggplotly()
have the default alignment (to the left). Is there an option to force the HTML widgets to the center?
EDIT: example given below.
---
title: "test"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.align = "center")
library(ggplot2)
library(plotly)
```
```{r static plot}
# This is aligned to center
g <- ggplot(mtcars, aes(mpg, cyl)) +
geom_point()
g
```
```{r html widget}
# html output isn't aligned
p <- ggplotly(g)
p
```