我用的是knitr::opts_chunk$set(fig.align = "center")
在rmarkdown文檔的開頭設定的數字排列。當我輸出HTML文件時,靜態數字與中心對齊,但HTML小部件(如leaflet()
和ggplotly()
的輸出)具有默認對齊方式(在左側)。有沒有一個選項可以強制HTML小部件到中心?HTML控件排列在rmarkdwon
編輯:下面給出的例子。
---
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
```
這可能幫助:https://stackoverflow.com/questions/39562947/how-to -arrange-html-widgets-inside-of-a-rmarkdown-document-pdf-html –
儘管可能有更好的方法,我通常使用CSS來定位HTML小部件。如果你發佈一個例子,我會很樂意演示。 –
以示例更新。 –