在 Rmarkdown HTML 输出中居中超大 ggplot 图

时间:2021-02-12 22:09:40

标签: html ggplot2 graphics r-markdown knitr

我正在 RStudio 中使用 Rmarkdown + knitr 编写报告。我有一个包含许多方面的 ggplot 图,只有在允许扩展到超出 HTML 输出中的文本宽度时才可读。我不介意在查看图表时必须水平滚动。我更改了下面 MWE 中的 HTML 样式以允许这种扩展。

尽管 knitr 中有 fig.align = "center" 选项,但图形具有所需的大小,但它与文本左对齐。是否可以将这种超大数字居中(即向文本边距的左侧和右侧均等扩展)?

---
title: "Title"
output: 
  html_document
---

<!-- remove limits on figure width -->
<style>
img {
    max-width: none;
}
</style>

```{r, include=FALSE}
knitr::opts_chunk$set(fig.align = "center")
library(tidyverse)
```

The following figure is left-aligned with text.

```{r, fig.width=15}
mtcars %>% 
  ggplot(aes(x = mpg, y = disp)) +
  geom_point()
```

0 个答案:

没有答案
相关问题