apexcharter/README.md

141 lines
3.1 KiB
Markdown
Raw Normal View History

2018-07-30 23:04:08 +02:00
# apexcharter
2019-02-14 18:33:35 +01:00
> Htmlwidget for [apexcharts.js](https://github.com/apexcharts/apexcharts.js) : A modern JavaScript charting library to build interactive charts and visualizations with simple API.
2018-07-30 23:04:08 +02:00
2018-09-09 21:21:42 +02:00
[![Travis build status](https://travis-ci.org/dreamRs/apexcharter.svg?branch=master)](https://travis-ci.org/dreamRs/apexcharter)
2019-02-14 18:33:35 +01:00
[![Project Status: WIP Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
2018-09-09 21:21:42 +02:00
2019-02-14 18:33:35 +01:00
:construction: Under development !! API will change :construction:
2019-02-14 09:59:08 +01:00
:warning: Use RStudio >= 1.2 to properly display charts
2019-02-14 18:33:35 +01:00
Note: Once again, development is heavily inspired by amazing [highcharter](http://jkunst.com/highcharter/).
2018-07-30 23:04:08 +02:00
## Installation
You can install the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("dreamRs/apexcharter")
```
2019-02-14 09:59:08 +01:00
2019-02-14 18:33:35 +01:00
## Quick Charts
Use `apex` function to quickly create visualizations :
```r
library(apexcharter)
data("mpg", package = "ggplot2")
n_manufac <- dplyr::count(mpg, manufacturer)
apex(data = n_manufac, type = "bar", mapping = aes(x = manufacturer, y = n))
```
![](man/figures/apex-bar.png)
With datetime:
```r
data("economics", package = "ggplot2")
apex(data = economics, type = "line", mapping = aes(x = date, y = uempmed)) %>%
ax_stroke(width = 1)
```
![](man/figures/apex-line.png)
## Full API
2018-07-31 23:24:35 +02:00
2019-02-14 18:40:32 +01:00
All methods from ApexCharts are available with function like `ax_*` compatible with pipe from `magrittr` :
2018-07-31 23:24:35 +02:00
```r
library(apexcharter)
2019-02-14 18:40:32 +01:00
data(mpg, package = "ggplot2")
n_manufac <- dplyr::count(mpg, manufacturer)
2018-07-31 23:24:35 +02:00
2019-02-14 09:22:57 +01:00
apexcharter() %>%
2018-07-31 23:24:35 +02:00
ax_chart(type = "bar") %>%
2018-08-03 11:10:36 +02:00
ax_plotOptions(bar = barOpts(
2018-07-31 23:24:35 +02:00
horizontal = FALSE,
endingShape = "flat",
columnWidth = "70%",
dataLabels = list(
position = "top"
))
) %>%
ax_grid(
show = TRUE,
2019-02-14 18:40:32 +01:00
position = "front",
borderColor = "#FFF"
2018-07-31 23:24:35 +02:00
) %>%
ax_series(list(
name = "Count",
2019-02-14 18:40:32 +01:00
data = n_manufac$n
2018-07-31 23:24:35 +02:00
)) %>%
ax_colors("#112446") %>%
2019-02-14 18:40:32 +01:00
ax_xaxis(categories = n_manufac$manufacturer) %>%
2018-07-31 23:24:35 +02:00
ax_title(text = "Number of models") %>%
ax_subtitle(text = "Data from ggplot2")
```
2019-02-14 18:40:32 +01:00
![](man/figures/apexcharter-full-bar.png)
2018-07-31 23:24:35 +02:00
2018-07-30 23:04:08 +02:00
## Raw API
2018-07-31 23:24:35 +02:00
Pass a list of parameters to the function:
2018-07-30 23:04:08 +02:00
``` r
2019-02-14 09:22:57 +01:00
apexcharter(ax_opts = list(
2018-07-30 23:04:08 +02:00
chart = list(
type = "line"
),
stroke = list(
curve = "smooth"
),
grid = list(
borderColor = "#e7e7e7",
row = list(
colors = c("#f3f3f3", "transparent"),
opacity = 0.5
)
),
dataLabels = list(
enabled = TRUE
),
markers = list(style = "inverted", size = 6),
series = list(
list(
name = "High",
data = c(28, 29, 33, 36, 32, 32, 33)
),
list(
name = "Low",
data = c(12, 11, 14, 18, 17, 13, 13)
)
),
title = list(
text = "Average High & Low Temperature",
align = "left"
),
xaxis = list(
categories = month.abb[1:7]
),
yaxis = list(
title = list(text = "Temperature"),
labels = list(
formatter = htmlwidgets::JS("function(value) {return value + '°C';}")
)
)
))
```
![alt text](img/raw-lines.png)