【问题标题】:Reduce too big gap between C3 widget and surrounding text in Rmarkdown减少 Rmarkdown 中 C3 小部件与周围文本之间的太大差距
【发布时间】:2020-10-21 13:37:21
【问题描述】:

我想使用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.

【问题讨论】:

    标签: r r-markdown c3.js htmlwidgets


    【解决方案1】:

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

    {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.
    

    这使得空白更小,但也让文本更小,但也许你可以玩这个,看看你是否能找到 R 块中的 fig.height 选项的解决方案

    【讨论】:

    • 谢谢,这也是我的第一个想法。但是看着元素,在我看来,空白来自 c3 而不是由于 HTML。都是svg标签,所以不知道哪个控制padding。最重要的是,它是C3 JS 中的一个插槽,我需要通过 R 接口进行设置。
    • 我添加到我的答案中,看看这是否可以帮助你
    • 谢谢这成功了。奇怪的是,现在只在c3 中设置高度似乎也可以渲染得很好。不知道发生了什么,但非常感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2020-05-25
    • 1970-01-01
    • 2015-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多