fixed typo and updated examples

This commit is contained in:
pvictor 2021-04-28 09:01:33 +02:00
parent e3efecf7f8
commit 1e42e587af
No known key found for this signature in database
GPG Key ID: 31124C9F3F9268B8
11 changed files with 341 additions and 336 deletions

View File

@ -50,7 +50,7 @@ apexcharter 0.1.5
## New functions
* `spark_box` to create boxes with sparkline, see corresponding vignette for more details.
* `add_shade()`, `add_shade_weekend()`, `add_event()` to add annotations on timeries charts.
* `add_shade()`, `add_shade_weekend()`, `add_event()` to add annotations on time-series charts.
* `add_hline()`, `add_vline()`, `add_point()` to add annotations on charts.
* `set_tooltip_fixed()` to fix tooltip in specific position.

View File

@ -40,7 +40,7 @@
#' @format A data frame with 120 observations and the following 3 variables:
#' \describe{
#' \item{\code{date}}{date.}
#' \item{\code{type}}{Type of data : realised or forecast.}
#' \item{\code{type}}{Type of data : realized or forecast.}
#' \item{\code{value}}{Value in giga-watt per hour.}
#' }
#' @source Rte (Electricity Transmission Network in France) (\url{https://data.rte-france.com/})

View File

@ -5,7 +5,6 @@
<!-- badges: start -->
[![version](http://www.r-pkg.org/badges/version/apexcharter)](https://CRAN.R-project.org/package=apexcharter)
[![cran checks](https://cranchecks.info/badges/worst/apexcharter)](https://cranchecks.info/pkgs/apexcharter)
[![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing)
[![R build status](https://github.com/dreamRs/apexcharter/workflows/R-CMD-check/badge.svg)](https://github.com/dreamRs/apexcharter/actions)
[![Codecov test coverage](https://codecov.io/gh/dreamRs/apexcharter/branch/master/graph/badge.svg)](https://codecov.io/gh/dreamRs/apexcharter?branch=master)
<!-- badges: end -->

View File

@ -1,14 +1,13 @@
## Test environments
* local OS Widows 10 install, R 3.6.3
* ubuntu 16.04, Windows 10, macOS (on GitHub Actions), R 4.0.2
* local OS Widows 10 install, R 4.0.3
* ubuntu 16.04, Windows 10, macOS (on GitHub Actions), R 4.0.5
* win-builder (devel and release)
## R CMD check results
0 errors | 0 warnings | 0 note
Updated JavaScript dependencies to include new chart type.
1 reverse dependencies checked, no new problems.
Updated JavaScript dependencies and new features.
Thank you!
Victor

View File

@ -1,20 +1,22 @@
library(apexcharter)
data("mpg", package = "ggplot2")
# Two chart side-by-side
a1 <- apex(mpg, aes(manufacturer), type = "bar")
a2 <- apex(mpg, aes(trans), type = "column")
apex_grid(a1, a2, height = "400px")
# More complex layout:
a3 <- apex(mpg, aes(drv), type = "pie")
apex_grid(
a1, a2, a3,
grid_area = c("1 / 1 / 3 / 2", "1 / 2 / 2 / 4", "2 / 2 / 3 / 4"),
ncol = 3, nrow = 2,
height = "600px"
)
if (interactive()) {
library(apexcharter)
data("mpg", package = "ggplot2")
# Two chart side-by-side
a1 <- apex(mpg, aes(manufacturer), type = "bar")
a2 <- apex(mpg, aes(trans), type = "column")
apex_grid(a1, a2, height = "400px")
# More complex layout:
a3 <- apex(mpg, aes(drv), type = "pie")
apex_grid(
a1, a2, a3,
grid_area = c("1 / 1 / 3 / 2", "1 / 2 / 2 / 4", "2 / 2 / 3 / 4"),
ncol = 3, nrow = 2,
height = "600px"
)
}

View File

@ -1,50 +1,50 @@
### Grid --------
library(apexcharter)
# Scatter ----
data("mpg", package = "ggplot2")
# Only rows
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_grid(rows = vars(drv), chart_height = "200px")
# Only cols
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_grid(cols = vars(year))
# Rows and Cols
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_grid(rows = vars(drv), cols = vars(year))
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_chart(toolbar = list(show = FALSE)) %>%
ax_facet_grid(vars(drv), vars(cyl))
# Labels
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_grid(
vars(drv),
labeller = function(x) {
switch(
x,
"f" = "front-wheel drive",
"r" = "rear wheel drive",
"4" = "4wd"
)
}
)
# Title and subtitle are treated as global
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_labs(
title = "Facet grid example",
subtitle = "mpg data from ggplot2"
) %>%
ax_facet_grid(rows = vars(drv), cols = vars(year))
if (interactive()) {
library(apexcharter)
# Scatter ----
data("mpg", package = "ggplot2")
# Only rows
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_grid(rows = vars(drv), chart_height = "200px")
# Only cols
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_grid(cols = vars(year))
# Rows and Cols
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_grid(rows = vars(drv), cols = vars(year))
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_chart(toolbar = list(show = FALSE)) %>%
ax_facet_grid(vars(drv), vars(cyl))
# Labels
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_grid(
vars(drv),
labeller = function(x) {
switch(
x,
"f" = "front-wheel drive",
"r" = "rear wheel drive",
"4" = "4wd"
)
}
)
# Title and subtitle are treated as global
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_labs(
title = "Facet grid example",
subtitle = "mpg data from ggplot2"
) %>%
ax_facet_grid(rows = vars(drv), cols = vars(year))
}

View File

@ -1,99 +1,101 @@
### Wrap --------
library(apexcharter)
# Scatter ----
data("mpg", package = "ggplot2")
# Create facets
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_wrap(vars(drv))
# Change number of columns
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_wrap(vars(drv), ncol = 2)
# Free axis
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_wrap(vars(drv), ncol = 2, scales = "free")
# labels
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_wrap(
vars(drv), ncol = 2,
labeller = function(x) {
switch(
x,
"f" = "front-wheel drive",
"r" = "rear wheel drive",
"4" = "4wd"
)
}
)
# Title and subtitle are treated as global
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_labs(
title = "Facet wrap example",
subtitle = "mpg data from ggplot2"
) %>%
ax_facet_wrap(vars(drv), ncol = 2)
# Multiple variables
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_wrap(vars(year, drv))
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_wrap(vars(year, drv), ncol = 2, nrow = 3)
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_chart(toolbar = list(show = FALSE)) %>%
ax_facet_wrap(
vars(year, drv),
labeller = function(x) {
paste(x, collapse = " / ")
}
)
# Lines ----
data("unhcr_ts")
refugees <- unhcr_ts %>%
subset(population_type == "Refugees (incl. refugee-like situations)") %>%
transform(date = as.Date(paste0(year, "-01-01")))
apex(refugees, aes(date, n), type = "line") %>%
ax_yaxis(tickAmount = 5) %>%
ax_facet_wrap(vars(continent_origin))
if (interactive()) {
library(apexcharter)
# Free y-axis and synchronize
apex(refugees, aes(date, n), type = "line", synchronize = "my-id") %>%
ax_yaxis(tickAmount = 5) %>%
ax_xaxis(tooltip = list(enabled = FALSE)) %>%
ax_tooltip(x = list(format = "yyyy")) %>%
ax_facet_wrap(vars(continent_origin), scales = "free_y")
# Scatter ----
# Bars ----
data("unhcr_ts")
refugees <- unhcr_ts %>%
subset(year == 2017)
apex(refugees, aes(continent_origin, n), type = "column") %>%
ax_yaxis(
labels = list(
formatter = format_num("~s")
),
tickAmount = 5
) %>%
ax_facet_wrap(vars(population_type), ncol = 2)
data("mpg", package = "ggplot2")
# Create facets
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_wrap(vars(drv))
# Change number of columns
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_wrap(vars(drv), ncol = 2)
# Free axis
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_wrap(vars(drv), ncol = 2, scales = "free")
# labels
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_wrap(
vars(drv), ncol = 2,
labeller = function(x) {
switch(
x,
"f" = "front-wheel drive",
"r" = "rear wheel drive",
"4" = "4wd"
)
}
)
# Title and subtitle are treated as global
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_labs(
title = "Facet wrap example",
subtitle = "mpg data from ggplot2"
) %>%
ax_facet_wrap(vars(drv), ncol = 2)
# Multiple variables
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_wrap(vars(year, drv))
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_wrap(vars(year, drv), ncol = 2, nrow = 3)
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_chart(toolbar = list(show = FALSE)) %>%
ax_facet_wrap(
vars(year, drv),
labeller = function(x) {
paste(x, collapse = " / ")
}
)
# Lines ----
data("unhcr_ts")
refugees <- unhcr_ts %>%
subset(population_type == "Refugees (incl. refugee-like situations)") %>%
transform(date = as.Date(paste0(year, "-01-01")))
apex(refugees, aes(date, n), type = "line") %>%
ax_yaxis(tickAmount = 5) %>%
ax_facet_wrap(vars(continent_origin))
# Free y-axis and synchronize
apex(refugees, aes(date, n), type = "line", synchronize = "my-id") %>%
ax_yaxis(tickAmount = 5) %>%
ax_xaxis(tooltip = list(enabled = FALSE)) %>%
ax_tooltip(x = list(format = "yyyy")) %>%
ax_facet_wrap(vars(continent_origin), scales = "free_y")
# Bars ----
data("unhcr_ts")
refugees <- unhcr_ts %>%
subset(year == 2017)
apex(refugees, aes(continent_origin, n), type = "column") %>%
ax_yaxis(
labels = list(
formatter = format_num("~s")
),
tickAmount = 5
) %>%
ax_facet_wrap(vars(population_type), ncol = 2)
}

View File

@ -49,152 +49,154 @@ Facet wrap for ApexCharts
}
\examples{
### Wrap --------
library(apexcharter)
# Scatter ----
data("mpg", package = "ggplot2")
# Create facets
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_wrap(vars(drv))
# Change number of columns
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_wrap(vars(drv), ncol = 2)
# Free axis
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_wrap(vars(drv), ncol = 2, scales = "free")
# labels
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_wrap(
vars(drv), ncol = 2,
labeller = function(x) {
switch(
x,
"f" = "front-wheel drive",
"r" = "rear wheel drive",
"4" = "4wd"
)
}
)
# Title and subtitle are treated as global
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_labs(
title = "Facet wrap example",
subtitle = "mpg data from ggplot2"
) \%>\%
ax_facet_wrap(vars(drv), ncol = 2)
# Multiple variables
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_wrap(vars(year, drv))
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_wrap(vars(year, drv), ncol = 2, nrow = 3)
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_chart(toolbar = list(show = FALSE)) \%>\%
ax_facet_wrap(
vars(year, drv),
labeller = function(x) {
paste(x, collapse = " / ")
}
)
# Lines ----
data("unhcr_ts")
refugees <- unhcr_ts \%>\%
subset(population_type == "Refugees (incl. refugee-like situations)") \%>\%
transform(date = as.Date(paste0(year, "-01-01")))
apex(refugees, aes(date, n), type = "line") \%>\%
ax_yaxis(tickAmount = 5) \%>\%
ax_facet_wrap(vars(continent_origin))
if (interactive()) {
library(apexcharter)
# Free y-axis and synchronize
apex(refugees, aes(date, n), type = "line", synchronize = "my-id") \%>\%
ax_yaxis(tickAmount = 5) \%>\%
ax_xaxis(tooltip = list(enabled = FALSE)) \%>\%
ax_tooltip(x = list(format = "yyyy")) \%>\%
ax_facet_wrap(vars(continent_origin), scales = "free_y")
# Scatter ----
# Bars ----
data("unhcr_ts")
refugees <- unhcr_ts \%>\%
subset(year == 2017)
apex(refugees, aes(continent_origin, n), type = "column") \%>\%
ax_yaxis(
labels = list(
formatter = format_num("~s")
),
tickAmount = 5
) \%>\%
ax_facet_wrap(vars(population_type), ncol = 2)
data("mpg", package = "ggplot2")
# Create facets
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_wrap(vars(drv))
# Change number of columns
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_wrap(vars(drv), ncol = 2)
# Free axis
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_wrap(vars(drv), ncol = 2, scales = "free")
# labels
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_wrap(
vars(drv), ncol = 2,
labeller = function(x) {
switch(
x,
"f" = "front-wheel drive",
"r" = "rear wheel drive",
"4" = "4wd"
)
}
)
# Title and subtitle are treated as global
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_labs(
title = "Facet wrap example",
subtitle = "mpg data from ggplot2"
) \%>\%
ax_facet_wrap(vars(drv), ncol = 2)
# Multiple variables
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_wrap(vars(year, drv))
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_wrap(vars(year, drv), ncol = 2, nrow = 3)
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_chart(toolbar = list(show = FALSE)) \%>\%
ax_facet_wrap(
vars(year, drv),
labeller = function(x) {
paste(x, collapse = " / ")
}
)
# Lines ----
data("unhcr_ts")
refugees <- unhcr_ts \%>\%
subset(population_type == "Refugees (incl. refugee-like situations)") \%>\%
transform(date = as.Date(paste0(year, "-01-01")))
apex(refugees, aes(date, n), type = "line") \%>\%
ax_yaxis(tickAmount = 5) \%>\%
ax_facet_wrap(vars(continent_origin))
# Free y-axis and synchronize
apex(refugees, aes(date, n), type = "line", synchronize = "my-id") \%>\%
ax_yaxis(tickAmount = 5) \%>\%
ax_xaxis(tooltip = list(enabled = FALSE)) \%>\%
ax_tooltip(x = list(format = "yyyy")) \%>\%
ax_facet_wrap(vars(continent_origin), scales = "free_y")
# Bars ----
data("unhcr_ts")
refugees <- unhcr_ts \%>\%
subset(year == 2017)
apex(refugees, aes(continent_origin, n), type = "column") \%>\%
ax_yaxis(
labels = list(
formatter = format_num("~s")
),
tickAmount = 5
) \%>\%
ax_facet_wrap(vars(population_type), ncol = 2)
}
### Grid --------
library(apexcharter)
# Scatter ----
data("mpg", package = "ggplot2")
# Only rows
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_grid(rows = vars(drv), chart_height = "200px")
# Only cols
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_grid(cols = vars(year))
# Rows and Cols
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_grid(rows = vars(drv), cols = vars(year))
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_chart(toolbar = list(show = FALSE)) \%>\%
ax_facet_grid(vars(drv), vars(cyl))
# Labels
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_grid(
vars(drv),
labeller = function(x) {
switch(
x,
"f" = "front-wheel drive",
"r" = "rear wheel drive",
"4" = "4wd"
)
}
)
# Title and subtitle are treated as global
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_labs(
title = "Facet grid example",
subtitle = "mpg data from ggplot2"
) \%>\%
ax_facet_grid(rows = vars(drv), cols = vars(year))
if (interactive()) {
library(apexcharter)
# Scatter ----
data("mpg", package = "ggplot2")
# Only rows
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_grid(rows = vars(drv), chart_height = "200px")
# Only cols
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_grid(cols = vars(year))
# Rows and Cols
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_grid(rows = vars(drv), cols = vars(year))
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_chart(toolbar = list(show = FALSE)) \%>\%
ax_facet_grid(vars(drv), vars(cyl))
# Labels
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_grid(
vars(drv),
labeller = function(x) {
switch(
x,
"f" = "front-wheel drive",
"r" = "rear wheel drive",
"4" = "4wd"
)
}
)
# Title and subtitle are treated as global
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_labs(
title = "Facet grid example",
subtitle = "mpg data from ggplot2"
) \%>\%
ax_facet_grid(rows = vars(drv), cols = vars(year))
}
}

View File

@ -40,24 +40,26 @@ Create a grid of ApexCharts
You have to provide either height for the grid or individual chart height to make it work.
}
\examples{
library(apexcharter)
data("mpg", package = "ggplot2")
# Two chart side-by-side
a1 <- apex(mpg, aes(manufacturer), type = "bar")
a2 <- apex(mpg, aes(trans), type = "column")
apex_grid(a1, a2, height = "400px")
# More complex layout:
a3 <- apex(mpg, aes(drv), type = "pie")
apex_grid(
a1, a2, a3,
grid_area = c("1 / 1 / 3 / 2", "1 / 2 / 2 / 4", "2 / 2 / 3 / 4"),
ncol = 3, nrow = 2,
height = "600px"
)
if (interactive()) {
library(apexcharter)
data("mpg", package = "ggplot2")
# Two chart side-by-side
a1 <- apex(mpg, aes(manufacturer), type = "bar")
a2 <- apex(mpg, aes(trans), type = "column")
apex_grid(a1, a2, height = "400px")
# More complex layout:
a3 <- apex(mpg, aes(drv), type = "pie")
apex_grid(
a1, a2, a3,
grid_area = c("1 / 1 / 3 / 2", "1 / 2 / 2 / 4", "2 / 2 / 3 / 4"),
ncol = 3, nrow = 2,
height = "600px"
)
}
}

View File

@ -8,7 +8,7 @@
A data frame with 120 observations and the following 3 variables:
\describe{
\item{\code{date}}{date.}
\item{\code{type}}{Type of data : realised or forecast.}
\item{\code{type}}{Type of data : realized or forecast.}
\item{\code{value}}{Value in giga-watt per hour.}
}
}

View File

@ -19,8 +19,7 @@ knitr::opts_chunk$set(
library(apexcharter)
```
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html)
Create grid of charts with ApexCharts, currently it's possible to: