---
title: "Chart"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Chart}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup, warning=FALSE, message=FALSE}
library(toastui)
library(ggplot2)
library(dplyr)
```

Interactive charts with [tui-chart](https://ui.toast.com/tui-chart) library. Currently support is minimal since there's a lot of htmlwidgets for creating charts.


## Bars / columns

```{r columns}
count(mpg, class) %>% 
  chart(aes(class, n), type = "column") %>% 
  chart_options(legend = list(visible = FALSE))
```


```{r columns-dodge}
count(mpg, class, year) %>% 
  chart(aes(class, n, fill = year), type = "column") %>% 
  chart_options(legend = list(align = "bottom"))
```


## Scatter

```{r scatter}
chart(mpg, aes(displ, hwy), type = "scatter")
```


## Lines / Areas

```{r line}
chart(economics, aes(date, psavert), type = "line")
```

```{r lines}
economics_long %>% 
  filter(variable %in% c("psavert", "uempmed")) %>% 
  chart(caes(date, value, color = variable), type = "line")
```



## Heatmap

```{r heatmap}
txhousing %>% 
  filter(city == "Houston") %>%
  chart(aes(month, year, fill = sales), type = "heatmap")
```



## Treemap


```{r treemap}
chart(mpg, aes(manufacturer, model), "treemap") %>% 
  chart_options(
    series = list(
      dataLabels = list(visible = TRUE)
    )
  )
```


```{r treemap-values}
txhousing %>% 
  filter(year == 2015) %>% 
  group_by(city) %>% 
  summarise(sales = sum(sales)) %>% 
  chart(aes(city, value = sales, colorValue = sales), type = "treemap")
```



## Gauge

```{r gauge}
chart(list(Speed = 80), type = "gauge", height = "500px") %>% 
  chart_options(
    circularAxis = list(scale = list(min = 0, max = 90), title = "km/h"),
    series = list(angleRange = list(start = 225, end = 135)),
    plot = list(
      bands = list(
        list(range = c(0, 20), color = "#55bf3b"),
        list(range = c(20, 50), color = "#dddf0d"),
        list(range = c(50, 90), color = "#df5353")
      )
    ),
    theme = list(plot = list(bands = list(barWidth = 40)))
  )
```

