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 ## New functions
* `spark_box` to create boxes with sparkline, see corresponding vignette for more details. * `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. * `add_hline()`, `add_vline()`, `add_point()` to add annotations on charts.
* `set_tooltip_fixed()` to fix tooltip in specific position. * `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: #' @format A data frame with 120 observations and the following 3 variables:
#' \describe{ #' \describe{
#' \item{\code{date}}{date.} #' \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.} #' \item{\code{value}}{Value in giga-watt per hour.}
#' } #' }
#' @source Rte (Electricity Transmission Network in France) (\url{https://data.rte-france.com/}) #' @source Rte (Electricity Transmission Network in France) (\url{https://data.rte-france.com/})

View File

@ -5,7 +5,6 @@
<!-- badges: start --> <!-- badges: start -->
[![version](http://www.r-pkg.org/badges/version/apexcharter)](https://CRAN.R-project.org/package=apexcharter) [![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) [![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) [![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) [![Codecov test coverage](https://codecov.io/gh/dreamRs/apexcharter/branch/master/graph/badge.svg)](https://codecov.io/gh/dreamRs/apexcharter?branch=master)
<!-- badges: end --> <!-- badges: end -->

View File

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

View File

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

View File

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

View File

@ -1,99 +1,101 @@
### Wrap -------- ### Wrap --------
library(apexcharter)
# Scatter ---- if (interactive()) {
library(apexcharter)
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))
# Scatter ----
# 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")
data("mpg", package = "ggplot2")
# Bars ---- # Create facets
apex(mpg, aes(displ, cty), type = "scatter") %>%
data("unhcr_ts") ax_facet_wrap(vars(drv))
refugees <- unhcr_ts %>%
subset(year == 2017) # Change number of columns
apex(mpg, aes(displ, cty), type = "scatter") %>%
apex(refugees, aes(continent_origin, n), type = "column") %>% ax_facet_wrap(vars(drv), ncol = 2)
ax_yaxis(
labels = list( # Free axis
formatter = format_num("~s") apex(mpg, aes(displ, cty), type = "scatter") %>%
), ax_facet_wrap(vars(drv), ncol = 2, scales = "free")
tickAmount = 5
) %>% # labels
ax_facet_wrap(vars(population_type), ncol = 2) 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{ \examples{
### Wrap -------- ### Wrap --------
library(apexcharter)
# Scatter ---- if (interactive()) {
library(apexcharter)
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))
# Scatter ----
# 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")
data("mpg", package = "ggplot2")
# Bars ---- # Create facets
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
data("unhcr_ts") ax_facet_wrap(vars(drv))
refugees <- unhcr_ts \%>\%
subset(year == 2017) # Change number of columns
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
apex(refugees, aes(continent_origin, n), type = "column") \%>\% ax_facet_wrap(vars(drv), ncol = 2)
ax_yaxis(
labels = list( # Free axis
formatter = format_num("~s") apex(mpg, aes(displ, cty), type = "scatter") \%>\%
), ax_facet_wrap(vars(drv), ncol = 2, scales = "free")
tickAmount = 5
) \%>\% # labels
ax_facet_wrap(vars(population_type), ncol = 2) 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 -------- ### Grid --------
library(apexcharter) if (interactive()) {
library(apexcharter)
# Scatter ----
# Scatter ----
data("mpg", package = "ggplot2")
data("mpg", package = "ggplot2")
# Only rows
apex(mpg, aes(displ, cty), type = "scatter") \%>\% # Only rows
ax_facet_grid(rows = vars(drv), chart_height = "200px") 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") \%>\% # Only cols
ax_facet_grid(cols = vars(year)) apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_grid(cols = vars(year))
# Rows and Cols
apex(mpg, aes(displ, cty), type = "scatter") \%>\% # Rows and Cols
ax_facet_grid(rows = vars(drv), cols = vars(year)) 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)) \%>\% apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_grid(vars(drv), vars(cyl)) ax_chart(toolbar = list(show = FALSE)) \%>\%
ax_facet_grid(vars(drv), vars(cyl))
# Labels
apex(mpg, aes(displ, cty), type = "scatter") \%>\% # Labels
ax_facet_grid( apex(mpg, aes(displ, cty), type = "scatter") \%>\%
vars(drv), ax_facet_grid(
labeller = function(x) { vars(drv),
switch( labeller = function(x) {
x, switch(
"f" = "front-wheel drive", x,
"r" = "rear wheel drive", "f" = "front-wheel drive",
"4" = "4wd" "r" = "rear wheel drive",
) "4" = "4wd"
} )
) }
)
# Title and subtitle are treated as global
apex(mpg, aes(displ, cty), type = "scatter") \%>\% # Title and subtitle are treated as global
ax_labs( apex(mpg, aes(displ, cty), type = "scatter") \%>\%
title = "Facet grid example", ax_labs(
subtitle = "mpg data from ggplot2" title = "Facet grid example",
) \%>\% subtitle = "mpg data from ggplot2"
ax_facet_grid(rows = vars(drv), cols = vars(year)) ) \%>\%
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. You have to provide either height for the grid or individual chart height to make it work.
} }
\examples{ \examples{
library(apexcharter) if (interactive()) {
data("mpg", package = "ggplot2") library(apexcharter)
data("mpg", package = "ggplot2")
# Two chart side-by-side
a1 <- apex(mpg, aes(manufacturer), type = "bar") # Two chart side-by-side
a1 <- apex(mpg, aes(manufacturer), type = "bar")
a2 <- apex(mpg, aes(trans), type = "column")
a2 <- apex(mpg, aes(trans), type = "column")
apex_grid(a1, a2, height = "400px")
apex_grid(a1, a2, height = "400px")
# More complex layout:
a3 <- apex(mpg, aes(drv), type = "pie") # More complex layout:
a3 <- apex(mpg, aes(drv), type = "pie")
apex_grid(
a1, a2, a3, apex_grid(
grid_area = c("1 / 1 / 3 / 2", "1 / 2 / 2 / 4", "2 / 2 / 3 / 4"), a1, a2, a3,
ncol = 3, nrow = 2, grid_area = c("1 / 1 / 3 / 2", "1 / 2 / 2 / 4", "2 / 2 / 3 / 4"),
height = "600px" ncol = 3, nrow = 2,
) height = "600px"
)
}
} }

View File

@ -8,7 +8,7 @@
A data frame with 120 observations and the following 3 variables: A data frame with 120 observations and the following 3 variables:
\describe{ \describe{
\item{\code{date}}{date.} \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.} \item{\code{value}}{Value in giga-watt per hour.}
} }
} }

View File

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