减少 Rmarkdown 中 C3 小部件和周围文本之间的太大差距

Reduce too big gap between C3 widget and surrounding text in Rmarkdown

我想使用 library(c3) 在我的 rmarkdown 文档中包含一个仪表图。但是,差距太大了:

---
title: "Gauge"
output: html_document
---

# Gauge

Too big gap to the gauge:

```{r, echo = FALSE, message = FALSE}
library(c3)
data.frame(x = 50) %>%
   c3() %>%
   c3_gauge()
```
This is fine.

这会产生以下输出:

仪表和文字上方的空白太大。我怎样才能减少它?在 c3 中玩 height/width 没有帮助。


在 @Daniel 的回答之后,我尝试了几个选项,与我的第一次尝试相反,设置 ehitgh 确实起到了作用(就像改变无花果高度一样) - 奇怪:

---
title: "Gauge"
output: html_document
---

# Gauge

Too big gap to the gauge:

```{r, echo = FALSE, message = FALSE}
library(c3)
data.frame(x = 50) %>%
   c3() %>%
   c3_gauge()
```
This is fine.

# Gauge fig.height = 2, height = 200

Too big gap to the gauge:

```{r, echo = FALSE, message = FALSE, fig.height=2}
library(c3)
data.frame(x = 50) %>%
   c3(height = 200) %>%
   c3_gauge()
```
This is fine.

# Gauge height = 200

Too big gap to the gauge:

```{r, echo = FALSE, message = FALSE}
library(c3)
data.frame(x = 50) %>%
   c3(height = 200) %>%
   c3_gauge()
```
This is fine.

# Gauge fig.height = 2

Too big gap to the gauge:

```{r, echo = FALSE, message = FALSE, fig.height=2}
library(c3)
data.frame(x = 50) %>%
   c3() %>%
   c3_gauge()
```
This is fine.

如果你知道 CSS 你可以尝试将它添加到你的 Rmarkdown 中,就像一个 R 块一样,但由于 webdev 知识有限,我无法从 inspect 元素中获得正确的属性标签。也许这与网页的填充有关

{css echo=FALSE}
.c3-chart {
  height: 200px; 
}

另外我又做了一次编辑,希望对你有帮助。

---
title: "Gauge"
output: html_document
---

# Gauge

Too big gap to the gauge:

```{r, echo = FALSE, message = FALSE, fig.height=2}
library(c3)
data.frame(x = 50) %>%
   c3() %>%
   c3_gauge()
```
This is fine.

这使白色 space 变小了,但也使文本变小了,但也许你可以尝试一下,看看是否可以使用 R 块中的 fig.height 选项找到解决方案