From 1e42e587af95f8749508eb57940a44c680ff949a Mon Sep 17 00:00:00 2001 From: pvictor Date: Wed, 28 Apr 2021 09:01:33 +0200 Subject: [PATCH] fixed typo and updated examples --- NEWS.md | 2 +- R/data.R | 2 +- README.md | 1 - cran-comments.md | 7 +- examples/apex_grid.R | 42 +++--- examples/facet_grid.R | 96 +++++++------- examples/facet_wrap.R | 192 ++++++++++++++-------------- man/apex-facets.Rd | 288 +++++++++++++++++++++--------------------- man/apex_grid.Rd | 42 +++--- man/consumption.Rd | 2 +- vignettes/facets.Rmd | 3 +- 11 files changed, 341 insertions(+), 336 deletions(-) diff --git a/NEWS.md b/NEWS.md index 49df0f2..b6720ae 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/R/data.R b/R/data.R index ff3b614..c19cae0 100644 --- a/R/data.R +++ b/R/data.R @@ -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/}) diff --git a/README.md b/README.md index 8662b76..520f7cd 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ [![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) diff --git a/cran-comments.md b/cran-comments.md index 37aae9e..dffcd69 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -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 diff --git a/examples/apex_grid.R b/examples/apex_grid.R index 79ece32..e275337 100644 --- a/examples/apex_grid.R +++ b/examples/apex_grid.R @@ -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" + ) +} diff --git a/examples/facet_grid.R b/examples/facet_grid.R index 7ac64f0..0842aca 100644 --- a/examples/facet_grid.R +++ b/examples/facet_grid.R @@ -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)) + +} diff --git a/examples/facet_wrap.R b/examples/facet_wrap.R index 97df80c..09a0942 100644 --- a/examples/facet_wrap.R +++ b/examples/facet_wrap.R @@ -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) + +} diff --git a/man/apex-facets.Rd b/man/apex-facets.Rd index 342602a..ab7d46a 100644 --- a/man/apex-facets.Rd +++ b/man/apex-facets.Rd @@ -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)) + +} } diff --git a/man/apex_grid.Rd b/man/apex_grid.Rd index 01841f4..4747d31 100644 --- a/man/apex_grid.Rd +++ b/man/apex_grid.Rd @@ -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" + ) +} } diff --git a/man/consumption.Rd b/man/consumption.Rd index be28411..3e593c8 100644 --- a/man/consumption.Rd +++ b/man/consumption.Rd @@ -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.} } } diff --git a/vignettes/facets.Rmd b/vignettes/facets.Rmd index f0aaa49..1a889bb 100644 --- a/vignettes/facets.Rmd +++ b/vignettes/facets.Rmd @@ -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: