apexcharter/vignettes/labs.Rmd

121 lines
2.5 KiB
Plaintext

---
title: "Labs: title, subtitle & axis"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{labs}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
Packages and data used below:
```{r message=FALSE, warning=FALSE}
library(apexcharter)
library(dplyr)
data("diamonds", package = "ggplot2")
n_cut <- count(diamonds, cut)
```
## Labs
You can set title, subtitle and axis' titles at once with `ax_labs()`:
```{r}
apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
ax_labs(
title = "Cut distribution",
subtitle = "Data from ggplot2",
x = "Cut",
y = "Count"
)
```
If you more control (font size, alignment, ...), you can use `ax_title()`, `ax_subtitle()`, `ax_xaxis()` and `ax_yaxis()`, as described below.
## Title
```{r}
apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
ax_title(text = "Cut distribution")
```
You can set some options, for example:
```{r}
apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
ax_title(
text = "Cut distribution",
align = "center",
style = list(fontSize = "22px", fontWeight = 700)
)
```
Full list of parameters is available here : https://apexcharts.com/docs/options/title/
## Subtitle
```{r}
apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
ax_title(text = "Cut distribution") %>%
ax_subtitle(text = "Data from ggplot2")
```
With same options than for title:
```{r}
apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
ax_title(
text = "Cut distribution",
align = "center",
style = list(fontSize = "22px", fontWeight = 700)
) %>%
ax_subtitle(
text = "Data from ggplot2",
align = "center",
style = list(fontSize = "16px", fontWeight = 400, color = "#BDBDBD")
)
```
Full list of parameters is available here : https://apexcharts.com/docs/options/subtitle/
## Axis title
```{r}
apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
ax_yaxis(title = list(text = "Count")) %>%
ax_xaxis(title = list(text = "Cut"))
```
With some options:
```{r}
apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
ax_yaxis(title = list(
text = "Count",
style = list(fontSize = "14px", color = "#BDBDBD")
)) %>%
ax_xaxis(title = list(
text = "Cut",
style = list(fontSize = "14px", color = "#BDBDBD")
))
```