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

151 views Asked by At

I want to include an gauge plot in my rmarkdown document using library(c3). However, the gap is too big:

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

This results in this output:

Gauge

The whitespace above the gauge and the text is too big. How can I reduce it? Playing with height/width in c3 did not help.


After the answer of @Daniel I played with several options and contrary to my first attempts, setting the ehitgh did do the trick (as did changing the fig height) - weired:

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

There are 1 answers

3
Daniel_j_iii On BEST ANSWER

If you know CSS you can try adding it in your Rmarkdown, just like an R chunk, but I was not able to get the right attribute tag from the inspect element, due to limited webdev knowledge. Maybe this has to do with the padding of the webpage

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

Also I made another edit and maybe it can help you, I hope.

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

This made the white space smaller, but also made the text smaller, but maybe you can play with this and see if you can find a solution with the fig.height options in the R chunk

enter image description here