【发布时间】:2017-06-09 13:21:27
【问题描述】:
我使用 rmarkdown 文档开头的knitr::opts_chunk$set(fig.align = "center") 来设置数字的对齐方式。当我输出 HTML 文件时,静态图形与中心对齐,但 HTML 小部件(例如来自 leaflet() 和 ggplotly() 的输出)具有默认对齐方式(向左)。是否有强制 HTML 小部件居中的选项?
编辑:下面给出的示例。
---
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
```
【问题讨论】:
-
虽然可能有更好的方法,但我通常使用 CSS 来定位 HTML 小部件。如果您发布示例,我很乐意展示。
-
已更新示例。
标签: r knitr r-markdown