diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 505132a..80e213a 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -60,7 +60,7 @@
diff --git a/docs/articles/index.html b/docs/articles/index.html index 41299b7..8c157e0 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -60,7 +60,7 @@ diff --git a/docs/articles/starting-with-apexcharts.html b/docs/articles/starting-with-apexcharts.html index febe00e..9815a81 100644 --- a/docs/articles/starting-with-apexcharts.html +++ b/docs/articles/starting-with-apexcharts.html @@ -30,7 +30,7 @@ @@ -74,13 +74,13 @@ -vignettes/starting-with-apexcharts.Rmd
starting-with-apexcharts.Rmd
The objective of this vignette is to show how to quickly build data visualizations with the ApexCharts JavaScript library, as well as to give an overview of the different graphics available.
Data used are from ggplot2
package, data manipulation will be done with the dplyr
package.
library(ggplot2)
-library(dplyr)
-#>
-#> Attachement du package : 'dplyr'
-#> The following objects are masked from 'package:stats':
-#>
-#> filter, lag
-#> The following objects are masked from 'package:base':
-#>
-#> intersect, setdiff, setequal, union
-library(apexcharter)
library(ggplot2)
+library(dplyr)
+#>
+#> Attachement du package : 'dplyr'
+#> The following objects are masked from 'package:stats':
+#>
+#> filter, lag
+#> The following objects are masked from 'package:base':
+#>
+#> intersect, setdiff, setequal, union
+library(apexcharter)
Simple bar charts can be created with:
-data("mpg")
-n_manufac <- count(mpg, manufacturer)
-
-apex(data = n_manufac, type = "column", mapping = aes(x = manufacturer, y = n))
Flipping coordinates can be done by using type = "bar"
:
To create a dodge bar charts, use aesthetic fill
:
n_manufac_year <- count(mpg, manufacturer, year)
-
-apex(data = n_manufac_year, type = "column", mapping = aes(x = manufacturer, y = n, fill = year))
For stacked bar charts, specify option stacked
in ax_chart
:
apex(data = n_manufac_year, type = "column", mapping = aes(x = manufacturer, y = n, fill = year)) %>%
- ax_chart(stacked = TRUE)
data("mpg")
+n_manufac <- count(mpg, manufacturer)
+
+apex(data = n_manufac, type = "column", mapping = aes(x = manufacturer, y = n))
Flipping coordinates can be done by using type = "bar"
:
To create a dodge bar charts, use aesthetic fill
:
n_manufac_year <- count(mpg, manufacturer, year)
+
+apex(data = n_manufac_year, type = "column", mapping = aes(x = manufacturer, y = n, fill = year))
For stacked bar charts, specify option stacked
in ax_chart
:
Simple line charts can be created with (works with character
, Date
or POSIXct
):
data("economics")
-economics <- head(economics, 100)
-
-apex(data = economics, type = "line", mapping = aes(x = date, y = uempmed))
To represent several lines, use a data.frame
in long format and the group
aesthetic:
economics_long <- economics_long %>%
- group_by(variable) %>%
- slice(1:100)
-
-apex(data = economics_long, type = "line", mapping = aes(x = date, y = value01, group = variable))
Create area charts with type = "area"
:
apex(data = economics_long, type = "area", mapping = aes(x = date, y = value01, fill = variable)) %>%
- ax_chart(stacked = TRUE) %>%
- ax_dataLabels(enabled = FALSE)
data("economics")
+economics <- tail(economics, 100)
+
+apex(data = economics, type = "line", mapping = aes(x = date, y = uempmed))
To represent several lines, use a data.frame
in long format and the group
aesthetic:
data("economics_long")
+economics_long <- economics_long %>%
+ group_by(variable) %>%
+ slice((n()-100):n())
+
+apex(data = economics_long, type = "line", mapping = aes(x = date, y = value01, group = variable))
Create area charts with type = "area"
:
Simple bar charts can be created with:
- - -Color points according to a third variable:
- - -And change point size using z
aesthetics:
Color points according to a third variable:
+apex(data = mtcars, type = "scatter", mapping = aes(x = wt, y = mpg, fill = cyl)) %>%
+ ax_xaxis(tickAmount = 5)
And change point size using z
aesthetics:
Simple pie charts can be created with:
-poll <- data.frame(
- answer = c("Yes", "No"),
- n = c(254, 238)
-)
-
-apex(data = poll, type = "pie", mapping = aes(x = answer, y = n))
Simple radial charts can be created with (here we pass values directly in aes
, but you can use a data.frame
) :
Multi radial chart (more than one value):
-fruits <- data.frame(
- name = c('Apples', 'Oranges', 'Bananas', 'Berries'),
- value = c(44, 55, 67, 83)
-)
-
-apex(data = fruits, type = "radialBar", mapping = aes(x = name, y = value))
Multi radial chart (more than one value):
+ + +Simple radar charts can be created with:
-mtcars$model <- rownames(mtcars)
-
-apex(data = head(mtcars), type = "radar", mapping = aes(x = model, y = qsec))
With a grouping variable:
-# extremely complicated reshaping
-new_mtcars <- reshape(
- data = head(mtcars),
- idvar = "model",
- varying = list(c("drat", "wt")),
- times = c("drat", "wt"),
- direction = "long",
- v.names = "value",
- drop = c("mpg", "cyl", "hp", "dist", "qsec", "vs", "am", "gear", "carb")
-)
-
-apex(data = new_mtcars, type = "radar", mapping = aes(x = model, y = value, group = time))
mtcars$model <- rownames(mtcars)
+
+apex(data = head(mtcars), type = "radar", mapping = aes(x = model, y = qsec))
With a grouping variable:
+# extremely complicated reshaping
+new_mtcars <- reshape(
+ data = head(mtcars),
+ idvar = "model",
+ varying = list(c("drat", "wt")),
+ times = c("drat", "wt"),
+ direction = "long",
+ v.names = "value",
+ drop = c("mpg", "cyl", "hp", "dist", "qsec", "vs", "am", "gear", "carb")
+)
+
+apex(data = new_mtcars, type = "radar", mapping = aes(x = model, y = value, group = time))
Create heatmap with :
-txhousing2 <- txhousing %>%
- filter(city %in% head(unique(city)), year %in% c(2000, 2001)) %>%
- rename(val_med = median)
-
-apex(data = txhousing2, type = "heatmap", mapping = aes(x = date, y = scales::rescale(val_med), group = city)) %>%
- ax_dataLabels(enabled = FALSE) %>%
- ax_colors("#008FFB")
txhousing2 <- txhousing %>%
+ filter(city %in% head(unique(city)), year %in% c(2000, 2001)) %>%
+ rename(val_med = median)
+
+apex(data = txhousing2,
+ type = "heatmap",
+ mapping = aes(x = date, y = scales::rescale(val_med), group = city)) %>%
+ ax_dataLabels(enabled = FALSE) %>%
+ ax_colors("#008FFB")
Htmlwidget for apexcharts.js : A modern JavaScript charting library to build interactive charts and visualizations with simple API.
-🚧 Under development !! API will change 🚧
-⚠️ Use RStudio >= 1.2 to properly display charts
+🚧 Under development !! API will change 🚧
+⚠️ Use RStudio >= 1.2 to properly display charts
Note: Once again, development is heavily inspired by amazing highcharter.
You can install the development version from GitHub with:
-# install.packages("devtools")
-devtools::install_github("dreamRs/apexcharter")
Use apex
function to quickly create visualizations :
library(apexcharter)
-
-data("mpg", package = "ggplot2")
-n_manufac <- dplyr::count(mpg, manufacturer)
-
-apex(data = n_manufac, type = "bar", mapping = aes(x = manufacturer, y = n))
library(apexcharter)
+
+data("mpg", package = "ggplot2")
+n_manufac <- dplyr::count(mpg, manufacturer)
+
+apex(data = n_manufac, type = "bar", mapping = aes(x = manufacturer, y = n))
With datetime:
- +All methods from ApexCharts are available with function like ax_*
compatible with pipe from magrittr
:
library(apexcharter)
-data(mpg, package = "ggplot2")
-n_manufac <- dplyr::count(mpg, manufacturer)
-
-apexchart() %>%
- ax_chart(type = "bar") %>%
- ax_plotOptions(bar = bar_opts(
- horizontal = FALSE,
- endingShape = "flat",
- columnWidth = "70%",
- dataLabels = list(
- position = "top"
- ))
- ) %>%
- ax_grid(
- show = TRUE,
- position = "front",
- borderColor = "#FFF"
- ) %>%
- ax_series(list(
- name = "Count",
- data = n_manufac$n
- )) %>%
- ax_colors("#112446") %>%
- ax_xaxis(categories = n_manufac$manufacturer) %>%
- ax_title(text = "Number of models") %>%
- ax_subtitle(text = "Data from ggplot2")
library(apexcharter)
+data(mpg, package = "ggplot2")
+n_manufac <- dplyr::count(mpg, manufacturer)
+
+apexchart() %>%
+ ax_chart(type = "bar") %>%
+ ax_plotOptions(bar = bar_opts(
+ horizontal = FALSE,
+ endingShape = "flat",
+ columnWidth = "70%",
+ dataLabels = list(
+ position = "top"
+ ))
+ ) %>%
+ ax_grid(
+ show = TRUE,
+ position = "front",
+ borderColor = "#FFF"
+ ) %>%
+ ax_series(list(
+ name = "Count",
+ data = n_manufac$n
+ )) %>%
+ ax_colors("#112446") %>%
+ ax_xaxis(categories = n_manufac$manufacturer) %>%
+ ax_title(text = "Number of models") %>%
+ ax_subtitle(text = "Data from ggplot2")
Pass a list of parameters to the function:
-apexchart(ax_opts = list(
- 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';}")
- )
- )
-))
apexchart(ax_opts = list(
+ 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';}")
+ )
+ )
+))
Specify the chart type. Available Options: "column"
, "bar"
, "line"
,
-"area"
, "spline"
, "pie"
, "donut"
, "radialBar"
, "radar"
, "scatter"
, "bubble"
, "heatmap"
.
"area"
, "spline"
, "pie"
, "donut"
, "radialBar"
, "radar"
, "scatter"
, "heatmap"
.