change fun name & data example

This commit is contained in:
pvictor 2019-02-14 09:22:57 +01:00
parent 633d0e3f3b
commit 74b92b3273
22 changed files with 544 additions and 40 deletions

View File

@ -1,3 +1,4 @@
^data-raw$
^\.travis\.yml$
^apexcharter\.Rproj$
^\.Rproj\.user$

View File

@ -1,5 +1,5 @@
Package: apexcharter
Version: 0.0.0.9600
Version: 0.0.1.900
Title: Create Interactive Chart with the JavaScript 'ApexCharts' Library
Description: Provides an 'htmlwidgets' interface to 'apexcharts.js'.
Authors@R: c(

View File

@ -1,9 +1,9 @@
# Generated by roxygen2: do not edit by hand
export("%>%")
export(apexchart)
export(apexchartOutput)
export(apexchartProxy)
export(apexcharter)
export(ax_annotations)
export(ax_chart)
export(ax_colors)

View File

@ -384,14 +384,14 @@ ax_responsive <- function(ax, ...) {
#' @examples
#'
#' # One serie
#' apexchart() %>%
#' apexcharter() %>%
#' ax_series(list(
#' name = "rnorm",
#' data = rnorm(10)
#' ))
#'
#' # Two series
#' apexchart() %>%
#' apexcharter() %>%
#' ax_series(
#' list(
#' name = "rnorm 1",

View File

@ -1,8 +1,8 @@
#' Create a apexcharts.js widget
#'
#' @param ax_opts A \code{list} in JSON format with chart parameters
#' @param data A \code{data.frame}.
#' @param data Default dataset to use for chart. If not already a \code{data.frame}, it will be coerced to with \code{as.data.frame}.
#' @param ax_opts A \code{list} in JSON format with chart parameters.#'
#' @param width A numeric input in pixels.
#' @param height A numeric input in pixels.
#' @param elementId Use an explicit element ID for the widget.
@ -16,7 +16,7 @@
#'
#' library(apexcharter)
#'
#' apexchart(ax_opts = list(
#' apexcharter(ax_opts = list(
#' chart = list(type = "bar"),
#' series = list(list(
#' name = "Example",
@ -24,12 +24,12 @@
#' )),
#' xaxis = list(categories = LETTERS[1:5])
#' ))
apexchart <- function(ax_opts = list(), data = NULL, width = NULL, height = NULL, elementId = NULL) {
apexcharter <- function(data = NULL, ax_opts = list(), width = NULL, height = NULL, elementId = NULL) {
# forward options using x
x <- list(
ax_opts = ax_opts,
data = data
data = as.data.frame(data)
)
# create widget

18
R/data.R Normal file
View File

@ -0,0 +1,18 @@
#' UNHCR data for 2017
#'
#' The dataset contains data about UNHCR's populations of concern for the year 2017.
#'
#' @format A data frame with 11237 observations on the following 6 variables.
#' \describe{
#' \item{\code{country_origin}}{Country of origin of population}
#' \item{\code{country_residence}}{Country / territory of asylum/residence of population}
#' \item{\code{population_type}}{Populations of concern : Refugees, Asylum-seekers, Internally displaced persons (IDPs), Returned refugees,
#' Returned IDPs, Stateless persons, Others of concern.}
#' \item{\code{value}}{Number of people concerned}
#' \item{\code{continent_residence}}{Continent of origin of population}
#' \item{\code{continent_origin}}{Continent of residence of population}
#' }
#' @source UNHCR (The UN Refugee Agency) (\url{http://popstats.unhcr.org/en/overview})
"unhcr_popstats_2017"

View File

@ -14,11 +14,11 @@ dropNulls <- function(x) {
#' Utility function to create ApexChart parameters JSON
#'
#' @param ax A \code{apexchart} \code{htmlwidget} object.
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
#' @param name Slot's name to edit
#' @param ... Arguments for the slot
#'
#' @return A \code{apexchart} \code{htmlwidget} object.
#' @return A \code{apexcharts} \code{htmlwidget} object.
#'
#' @importFrom utils modifyList
#'
@ -40,11 +40,11 @@ dropNulls <- function(x) {
#' Utility function to create ApexChart parameters JSON
#'
#' @param ax A \code{apexchart} \code{htmlwidget} object.
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
#' @param name Slot's name to edit
#' @param l List of arguments for the slot
#'
#' @return A \code{apexchart} \code{htmlwidget} object.
#' @return A \code{apexcharts} \code{htmlwidget} object.
#'
#' @noRd
.ax_opt2 <- function(ax, name, l) {

View File

@ -28,7 +28,7 @@ library(magrittr)
data(mpg)
dat <- count(mpg, manufacturer)
apexchart() %>%
apexcharter() %>%
ax_chart(type = "bar") %>%
ax_plotOptions(bar = barOpts(
horizontal = FALSE,
@ -60,7 +60,7 @@ apexchart() %>%
Pass a list of parameters to the function:
``` r
apexchart(ax_opts = list(
apexcharter(ax_opts = list(
chart = list(
type = "line"
),

View File

@ -0,0 +1,224 @@
# ------------------------------------------------------------------------
#
# Title : UNHCR - Persons of concerns (All)
# By : Victor
# Date : 2018-10-29
#
# ------------------------------------------------------------------------
# Package -----------------------------------------------------------------
library("data.table")
library("janitor")
library("ggplot2")
# Data --------------------------------------------------------------------
# http://popstats.unhcr.org/en/persons_of_concern/https://goo.gl/rcTJPz
unhcr_popstats <- fread(
input = "data-raw/unhcr_popstats_export_time_series_all_data.csv",
skip = 3,
na.strings = "*",
encoding = "UTF-8"
)
unhcr_popstats <- clean_names(unhcr_popstats)
unhcr_popstats
# Get Continent -----------------------------------------------------------
wrld <- rnaturalearth::countries110@data
setDT(wrld)
continents <- merge(
x = unique(rbind(
unique(unhcr_popstats[, list(country = country_territory_of_asylum_residence)]),
unique(unhcr_popstats[, list(country = origin)])
)),
y = wrld[, list(country = name_long, iso_a2, iso_a3, continent)],
all.x = TRUE
)
table(continents$continent, useNA = "a")
# Missing ones
cat(
paste(sprintf(
"continents[country == \"%s\", `:=`(iso_a2 = \"\", iso_a3 = \"\", continent = \"\")]",
continents$country[is.na(continents$continent)]
), collapse = "\n")
)
continents[country == "Anguilla", `:=`(iso_a2 = "AI", iso_a3 = "AIA", continent = "South America")]
continents[country == "Antigua and Barbuda", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "Aruba", `:=`(iso_a2 = "", iso_a3 = "", continent = "South America")]
continents[country == "Bahrain", `:=`(iso_a2 = "BH", iso_a3 = "BHR", continent = "Asia")]
continents[country == "Barbados", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "Bolivia (Plurinational State of)", `:=`(iso_a2 = "BO", iso_a3 = "", continent = "South America")]
continents[country == "Bonaire", `:=`(iso_a2 = "", iso_a3 = "", continent = "South America")]
continents[country == "British Virgin Islands", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "Cabo Verde", `:=`(iso_a2 = "", iso_a3 = "", continent = "Africa")]
continents[country == "Cayman Islands", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "Central African Rep.", `:=`(iso_a2 = "CF", iso_a3 = "CAF", continent = "Africa")]
continents[country == "China, Hong Kong SAR", `:=`(iso_a2 = "", iso_a3 = "", continent = "Asia")]
continents[country == "China, Macao SAR", `:=`(iso_a2 = "", iso_a3 = "", continent = "Asia")]
continents[country == "Comoros", `:=`(iso_a2 = "", iso_a3 = "", continent = "Africa")]
continents[country == "Congo", `:=`(iso_a2 = "", iso_a3 = "", continent = "Africa")]
continents[country == "Curaçao", `:=`(iso_a2 = "", iso_a3 = "", continent = "South America")]
continents[country == "Curaçao", `:=`(iso_a2 = "", iso_a3 = "", continent = "South America")]
continents[country == "Czech Rep.", `:=`(iso_a2 = "CZ", iso_a3 = "CZE", continent = "Europe")]
continents[country %like% "Ivoire", `:=`(iso_a2 = "", iso_a3 = "", continent = "Africa")]
continents[country == "Dem. People's Rep. of Korea", `:=`(iso_a2 = "", iso_a3 = "", continent = "Asia")]
continents[country == "Dem. Rep. of the Congo", `:=`(iso_a2 = "", iso_a3 = "", continent = "Africa")]
continents[country == "Dominican Rep.", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "French Guiana", `:=`(iso_a2 = "", iso_a3 = "", continent = "South America")]
continents[country == "Gambia", `:=`(iso_a2 = "", iso_a3 = "", continent = "Africa")]
continents[country == "Grenada", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "Iran (Islamic Rep. of)", `:=`(iso_a2 = "", iso_a3 = "", continent = "Asia")]
continents[country == "Lao People's Dem. Rep.", `:=`(iso_a2 = "", iso_a3 = "", continent = "Asia")]
continents[country == "Liechtenstein", `:=`(iso_a2 = "", iso_a3 = "", continent = "Europe")]
continents[country == "Malta", `:=`(iso_a2 = "", iso_a3 = "", continent = "Europe")]
continents[country == "Mauritius", `:=`(iso_a2 = "", iso_a3 = "", continent = "Africa")]
continents[country == "Micronesia (Federated States of)", `:=`(iso_a2 = "", iso_a3 = "", continent = "Oceania")]
continents[country == "Monaco", `:=`(iso_a2 = "", iso_a3 = "", continent = "Europe")]
continents[country == "Montserrat", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "Nauru", `:=`(iso_a2 = "", iso_a3 = "", continent = "Oceania")]
continents[country == "Palau", `:=`(iso_a2 = "", iso_a3 = "", continent = "Oceania")]
continents[country == "Rep. of Korea", `:=`(iso_a2 = "", iso_a3 = "", continent = "Asia")]
continents[country == "Rep. of Moldova", `:=`(iso_a2 = "", iso_a3 = "", continent = "Europe")]
continents[country == "Saint Kitts and Nevis", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "Saint Lucia", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "Saint Vincent and the Grenadines", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "Samoa", `:=`(iso_a2 = "", iso_a3 = "", continent = "Oceania")]
continents[country == "Serbia and Kosovo (S/RES/1244 (1999))", `:=`(iso_a2 = "", iso_a3 = "", continent = "Europe")]
continents[country == "Seychelles", `:=`(iso_a2 = "", iso_a3 = "", continent = "Africa")]
continents[country == "Singapore", `:=`(iso_a2 = "", iso_a3 = "", continent = "Asia")]
continents[country == "Sint Maarten (Dutch part)", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "State of Palestine", `:=`(iso_a2 = "", iso_a3 = "", continent = "Asia")]
continents[country == "Syrian Arab Rep.", `:=`(iso_a2 = "", iso_a3 = "", continent = "Asia")]
continents[country == "The former Yugoslav Republic of Macedonia", `:=`(iso_a2 = "", iso_a3 = "", continent = "Europe")]
continents[country == "Tonga", `:=`(iso_a2 = "", iso_a3 = "", continent = "Oceania")]
continents[country == "Turks and Caicos Islands", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "United Rep. of Tanzania", `:=`(iso_a2 = "TZ", iso_a3 = "", continent = "Africa")]
continents[country == "United States of America", `:=`(iso_a2 = "US", iso_a3 = "USA", continent = "North America")]
continents[country == "Venezuela (Bolivarian Republic of)", `:=`(iso_a2 = "", iso_a3 = "", continent = "South America")]
continents[country == "Viet Nam", `:=`(iso_a2 = "", iso_a3 = "", continent = "Asia")]
continents[country == "American Samoa", `:=`(iso_a2 = "", iso_a3 = "", continent = "Oceania")]
continents[country == "Andorra", `:=`(iso_a2 = "", iso_a3 = "", continent = "Europe")]
continents[country == "Bermuda", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "Cook Islands", `:=`(iso_a2 = "", iso_a3 = "", continent = "Oceania")]
continents[country == "Dominica", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "French Polynesia", `:=`(iso_a2 = "", iso_a3 = "", continent = "Oceania")]
continents[country == "Gibraltar", `:=`(iso_a2 = "", iso_a3 = "", continent = "Europe")]
continents[country == "Guadeloupe", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "Guam", `:=`(iso_a2 = "", iso_a3 = "", continent = "Oceania")]
# continents[country == "Holy See (the)", `:=`(iso_a2 = "", iso_a3 = "", continent = "")]
continents[country == "Kiribati", `:=`(iso_a2 = "", iso_a3 = "", continent = "Oceania")]
continents[country == "Maldives", `:=`(iso_a2 = "", iso_a3 = "", continent = "Asia")]
continents[country == "Marshall Islands", `:=`(iso_a2 = "", iso_a3 = "", continent = "Oceania")]
continents[country == "Martinique", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "Niue", `:=`(iso_a2 = "", iso_a3 = "", continent = "Oceania")]
continents[country == "Norfolk Island", `:=`(iso_a2 = "", iso_a3 = "", continent = "Oceania")]
continents[country == "Palestinian", `:=`(iso_a2 = "", iso_a3 = "", continent = "Asia")]
continents[country == "Saint-Pierre-et-Miquelon", `:=`(iso_a2 = "", iso_a3 = "", continent = "North America")]
continents[country == "San Marino", `:=`(iso_a2 = "", iso_a3 = "", continent = "Europe")]
continents[country == "Sao Tome and Principe", `:=`(iso_a2 = "", iso_a3 = "", continent = "Africa")]
# continents[country == "Stateless", `:=`(iso_a2 = "", iso_a3 = "", continent = "")]
continents[country == "Svalbard and Jan Mayen", `:=`(iso_a2 = "", iso_a3 = "", continent = "Europe")]
continents[country == "Tibetan", `:=`(iso_a2 = "", iso_a3 = "", continent = "Asia")]
continents[country == "Tuvalu", `:=`(iso_a2 = "", iso_a3 = "", continent = "Oceania")]
# continents[country == "Various/Unknown", `:=`(iso_a2 = "", iso_a3 = "", continent = "")]
continents[country == "Wallis and Futuna Islands", `:=`(iso_a2 = "", iso_a3 = "", continent = "Oceania")]
table(continents$continent, useNA = "a")
# origin
unique(unhcr_popstats$origin)[!unique(unhcr_popstats$origin) %in% continents$country]
unhcr_popstats <- merge(
x = unhcr_popstats, y = continents[, list(country, continent_residence = continent)],
by.x = "country_territory_of_asylum_residence", by.y = "country"
)
unhcr_popstats <- merge(
x = unhcr_popstats, y = continents[, list(country, continent_origin = continent)],
by.x = "origin", by.y = "country"
)
# Use data 2017 -----------------------------------------------------------
setnames(unhcr_popstats, "origin", "country_origin")
setnames(unhcr_popstats, "country_territory_of_asylum_residence", "country_residence")
unhcr_popstats[, country_residence := stringi::stri_trans_general(str = country_residence, id = "ASCII-Latin")]
unhcr_popstats[, country_origin := stringi::stri_trans_general(str = country_origin, id = "ASCII-Latin")]
unhcr_popstats_2017 <- unhcr_popstats[year == 2017, -c("year")]
unhcr_popstats_2017 <- as.data.frame(unhcr_popstats_2017)
head(unhcr_popstats_2017)
utils::promptData(object = unhcr_popstats_2017, filename = "tmp.Rd")
usethis::use_data(unhcr_popstats_2017, overwrite = TRUE)
# Explo -------------------------------------------------------------------
unhcr_popstats[year == 2017, list(total_population = sum(value, na.rm = TRUE)), by = continent_residence]
unhcr_popstats[year == 2017, list(total_population = sum(value, na.rm = TRUE)), by = continent_origin]
unhcr_popstats[year == 2017, list(total_population = sum(value, na.rm = TRUE)), by = list(continent_origin, continent_residence)]
ggplot(data = unhcr_popstats[year == 2017, list(total_population = sum(value, na.rm = TRUE)), by = continent_residence]) +
geom_col(aes(x = continent_residence, y = total_population))
ggplot(data = unhcr_popstats[year == 2017, list(total_population = sum(value, na.rm = TRUE)), by = continent_origin]) +
geom_col(aes(x = continent_origin, y = total_population))
ggplot(data = rbind(
unhcr_popstats[year == 2017 & population_type %like% "^Refugees",
list(total_population = sum(value, na.rm = TRUE), type = "from"),
by = list(continent = continent_origin)],
unhcr_popstats[year == 2017 & population_type %like% "^Refugees",
list(total_population = sum(value, na.rm = TRUE), type = "to"),
by = list(continent = continent_residence)]
)) +
geom_col(aes(x = continent, y = total_population, fill = type), position = "dodge")
unhcr_popstats[year == 2017, list(value = sum(value, na.rm = TRUE)), by = population_type]
ggplot(data = unhcr_popstats[year == 2017, list(value = sum(value, na.rm = TRUE)), by = population_type]) +
geom_col(aes(x = population_type, y = value))
unhcr_popstats[year == 2017, list(value = sum(value, na.rm = TRUE)), by = list(population_type, continent_residence)]

View File

@ -0,0 +1,61 @@
# ------------------------------------------------------------------------
#
# Title : UNCHR - Persons of concerns (France)
# By : Victor
# Date : 2018-10-29
#
# ------------------------------------------------------------------------
# Package -----------------------------------------------------------------
library("data.table")
library("janitor")
library("ggplot2")
# Data --------------------------------------------------------------------
# http://popstats.unhcr.org/en/persons_of_concern/https://goo.gl/rcTJPz
unhcr_popstats_fr <- fread(
input = "data-raw/unhcr_popstats_export_persons_of_concern_2018_10_29_143107.csv",
skip = 3,
na.strings = "*"
)
unhcr_popstats_fr <- clean_names(unhcr_popstats_fr)
unhcr_popstats_fr
# Origin countries of refugees in 2017 ------------------------------------
# excluding "Various/Unknown"
unhcr_fr_2017 <- unhcr_popstats_fr[origin != "Various/Unknown" & year == 2017, list(
origin,
refugees = refugees_incl_refugee_like_situations,
asylum_seekers = asylum_seekers_pending_cases,
total_population
)]
unhcr_fr_2017[order(total_population, decreasing = TRUE)][1:10]
ggplot(data = unhcr_fr_2017[order(total_population, decreasing = TRUE)][1:10]) +
geom_col(aes(x = origin, y = total_population))

Binary file not shown.

View File

@ -13,7 +13,7 @@ library(dplyr)
data(mpg)
dat <- count(mpg, manufacturer)
apexchart(ax_opts = list(
apexcharter(ax_opts = list(
chart = list(type = "bar"),
plotOptions = list(
bar = list(
@ -43,7 +43,7 @@ apexchart(ax_opts = list(
# recreating (mostly): https://apexcharts.com/javascript-chart-demos/line-charts/data-labels/
apexchart(ax_opts = list(
apexcharter(ax_opts = list(
chart = list(
type = "line"
),

View File

@ -23,7 +23,7 @@ library(dplyr) # for count
data(mpg)
dat <- count(mpg, manufacturer)
apexchart() %>%
apexcharter() %>%
ax_chart(type = "bar") %>%
ax_plotOptions(bar = barOpts(
horizontal = FALSE,
@ -55,7 +55,7 @@ apexchart() %>%
data(mpg)
dat <- count(mpg, manufacturer)
apexchart() %>%
apexcharter() %>%
ax_chart(type = "bar") %>%
ax_plotOptions(bar = barOpts(
horizontal = TRUE,
@ -86,7 +86,7 @@ apexchart() %>%
stacked <- count(mpg, manufacturer, year)
apexchart() %>%
apexcharter() %>%
ax_chart(type = "bar", stacked = TRUE) %>%
ax_series(
list(
@ -113,7 +113,7 @@ apexchart() %>%
stacked <- count(mpg, manufacturer, year)
apexchart() %>%
apexcharter() %>%
ax_chart(type = "bar", stacked = FALSE) %>%
ax_plotOptions(bar = barOpts(
endingShape = "rounded"

View File

@ -0,0 +1,174 @@
# ------------------------------------------------------------------------
#
# Title : apexcharter examples - UNHCR
# By : Victor
# Date : 2018-10-29
#
# ------------------------------------------------------------------------
# Package -----------------------------------------------------------------
library("apexcharter")
library("dplyr")
# Data --------------------------------------------------------------------
data("unhcr_popstats_2017")
head(unhcr_popstats_2017)
# Categories of people of concerns ----------------------------------------
categories_unhcr <- count(unhcr_popstats_2017, population_type, sort = TRUE)
apexcharter() %>%
ax_chart(type = "bar") %>%
ax_plotOptions(bar = barOpts(
horizontal = TRUE,
dataLabels = list(
position = "center"
))
) %>%
ax_grid(
show = TRUE,
yaxis = list(lines = list(show = FALSE)),
xaxis = list(lines = list(show = TRUE))
) %>%
ax_series(list(
name = "Number of persons of concern",
data = categories_unhcr$n
)) %>%
ax_colors("#112446") %>%
ax_xaxis(categories = categories_unhcr$population_type) %>%
ax_xaxis(title = list(text = "Number of persons of concern")) %>%
ax_title(text = "UNHCR's populations of concern in 2017") %>%
ax_subtitle(text = "Data from the UN Regugee Agency")
# Origin & Residence Refugees ---------------------------------------------
refugees <- unhcr_popstats_2017 %>%
filter(
population_type %in% "Refugees (incl. refugee-like situations)",
!is.na(continent_origin)
)
apexcharter() %>%
ax_chart(type = "bar", stacked = FALSE) %>%
ax_dataLabels(enabled = FALSE) %>%
ax_series(
list(
name = "Residence",
data = refugees %>%
count(continent_residence, wt = value) %>%
pull(n)
),
list(
name = "Origin",
data = refugees %>%
count(continent_origin, wt = value)
%>% pull(n)
)
) %>%
ax_colors("#58224f", "#b65165") %>%
ax_stroke(show = TRUE, width = 1, colors = list("#FFF")) %>%
ax_xaxis(
categories = refugees %>%
distinct(continent_origin) %>%
arrange(continent_origin) %>%
pull(continent_origin)
) %>%
ax_yaxis(
labels = list(
formatter = htmlwidgets::JS(
"function(val) {return val.toLocaleString();}"
)
)
) %>%
ax_tooltip(shared = TRUE) %>%
ax_legend(
position = "right",
verticalAlign = "top"
) %>%
ax_title(text = "Refugees Origin & Residence by continent in 2017") %>%
ax_subtitle(text = "Data from the UN Regugee Agency")
# Type of populations of concerns by continent ----------------------------
count(unhcr_popstats_2017, continent = continent_residence, population_type, wt = value)
apexcharter() %>%
ax_chart(type = "bar", stacked = TRUE, stackType = "100%") %>%
ax_plotOptions(bar = barOpts(horizontal = TRUE)) %>%
ax_series(
list(
name = "Asylum-seekers",
data = unhcr_popstats_2017 %>%
filter(population_type == "Asylum-seekers") %>%
count(continent_residence, wt = value) %>%
pull(n)
),
list(
name = "Refugees (incl. refugee-like situations)",
data = unhcr_popstats_2017 %>%
filter(population_type == "Refugees (incl. refugee-like situations)") %>%
count(continent_residence, wt = value) %>%
pull(n)
),
list(
name = "Internally displaced persons",
data = unhcr_popstats_2017 %>%
filter(population_type == "Internally displaced persons") %>%
count(continent_residence, wt = value) %>%
tidyr::complete(continent_residence = unique(unhcr_popstats_2017$continent_residence), fill = list(n = 0)) %>% # No Oceania !
pull(n)
),
list(
name = "Stateless persons",
data = unhcr_popstats_2017 %>%
filter(population_type == "Stateless persons") %>%
count(continent_residence, wt = value) %>%
pull(n)
)
) %>%
ax_xaxis(categories = sort(unique(unhcr_popstats_2017$continent_residence))) %>%
ax_yaxis(min = 0, max = 100,
tickAmount = 4) %>%
ax_xaxis(
labels = list(
formatter = htmlwidgets::JS(
"function(val) {return val + '%';}"
)
)
) %>%
ax_tooltip(shared = TRUE)

View File

@ -28,7 +28,7 @@ mtcars_long <- mtcars %>%
mtcars_long$value <- round(mtcars_long$value)
test <- apexchart() %>%
test <- apexcharter() %>%
ax_chart(type = "heatmap") %>%
ax_dataLabels(enabled = FALSE) %>%
ax_series2(lapply(
@ -46,7 +46,7 @@ test <- apexchart() %>%
ax_xaxis(type = "category", categories = unique(mtcars_long$variable))
apexchart() %>%
apexcharter() %>%
ax_chart(type = "heatmap") %>%
ax_dataLabels(enabled = FALSE) %>%
ax_series2(l = list(
@ -74,7 +74,7 @@ apexchart() %>%
data("vaccines", package = "highcharter")
apexchart() %>%
apexcharter() %>%
ax_chart(type = "heatmap", animations = list(enabled = FALSE)) %>%
ax_dataLabels(enabled = FALSE) %>%
ax_series2(lapply(

View File

@ -20,7 +20,7 @@ library(apexcharter)
# Simple pie --------------------------------------------------------------
apexchart() %>%
apexcharter() %>%
ax_chart(type = "pie") %>%
ax_series(23, 45, 56) %>%
ax_labels("A", "B", "C")
@ -31,7 +31,7 @@ apexchart() %>%
# Donut -------------------------------------------------------------------
apexchart() %>%
apexcharter() %>%
ax_chart(type = "donut") %>%
ax_series2(c(23, 45, 56)) %>%
ax_labels2(c("A", "B", "C"))

View File

@ -23,7 +23,7 @@ ui <- fluidPage(
server <- function(input, output, session) {
output$graph <- renderApexchart({
apexchart() %>%
apexcharter() %>%
ax_chart(type = "line") %>%
ax_plotOptions(line = list(curve = "smooth")) %>%
ax_dataLabels(enabled = FALSE) %>%

View File

@ -20,7 +20,7 @@ library(apexcharter)
# Basic -------------------------------------------------------------------
apexchart() %>%
apexcharter() %>%
ax_chart(type = "radialBar") %>%
ax_plotOptions(
radialBar = radialBarOpts(
@ -35,7 +35,7 @@ apexchart() %>%
# Stroked gauge -----------------------------------------------------------
apexchart() %>%
apexcharter() %>%
ax_chart(type = "radialBar") %>%
ax_plotOptions(
radialBar = radialBarOpts(

View File

@ -25,7 +25,7 @@ data("economics", package = "ggplot2")
# One serie (class Date) --------------------------------------------------
apexchart() %>%
apexcharter() %>%
ax_chart(type = "area", zoom = list(enabled = TRUE)) %>%
# ax_stroke(curve = "smooth") %>%
ax_plotOptions(line = list(curve = "smooth")) %>%
@ -62,7 +62,7 @@ apexchart() %>%
# Two series (Date) -------------------------------------------------------
apexchart() %>%
apexcharter() %>%
ax_chart(type = "line", zoom = list(enabled = TRUE)) %>%
ax_plotOptions(line = list(curve = "smooth")) %>%
ax_dataLabels(enabled = FALSE) %>%
@ -99,7 +99,7 @@ apexchart() %>%
# doesn't work since 2.0.0
apexchart() %>%
apexcharter() %>%
ax_chart(type = "area", scroller = list(enabled = TRUE)) %>%
ax_dataLabels(enabled = FALSE) %>%
ax_series(list(

View File

@ -1,16 +1,16 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/apexcharter.R
\name{apexchart}
\alias{apexchart}
\name{apexcharter}
\alias{apexcharter}
\title{Create a apexcharts.js widget}
\usage{
apexchart(ax_opts = list(), data = NULL, width = NULL,
apexcharter(data = NULL, ax_opts = list(), width = NULL,
height = NULL, elementId = NULL)
}
\arguments{
\item{ax_opts}{A \code{list} in JSON format with chart parameters}
\item{data}{Default dataset to use for chart. If not already a \code{data.frame}, it will be coerced to with \code{as.data.frame}.}
\item{data}{A \code{data.frame}.}
\item{ax_opts}{A \code{list} in JSON format with chart parameters.#'}
\item{width}{A numeric input in pixels.}
@ -28,7 +28,7 @@ Create a apexcharts.js widget
library(apexcharter)
apexchart(ax_opts = list(
apexcharter(ax_opts = list(
chart = list(type = "bar"),
series = list(list(
name = "Example",

View File

@ -26,14 +26,14 @@ Add data to a chart
\examples{
# One serie
apexchart() \%>\%
apexcharter() \%>\%
ax_series(list(
name = "rnorm",
data = rnorm(10)
))
# Two series
apexchart() \%>\%
apexcharter() \%>\%
ax_series(
list(
name = "rnorm 1",

View File

@ -0,0 +1,26 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.R
\docType{data}
\name{unhcr_popstats_2017}
\alias{unhcr_popstats_2017}
\title{UNHCR data for 2017}
\format{A data frame with 11237 observations on the following 6 variables.
\describe{
\item{\code{country_origin}}{Country of origin of population}
\item{\code{country_residence}}{Country / territory of asylum/residence of population}
\item{\code{population_type}}{Populations of concern : Refugees, Asylum-seekers, Internally displaced persons (IDPs), Returned refugees,
Returned IDPs, Stateless persons, Others of concern.}
\item{\code{value}}{Number of people concerned}
\item{\code{continent_residence}}{Continent of origin of population}
\item{\code{continent_origin}}{Continent of residence of population}
}}
\source{
UNHCR (The UN Refugee Agency) (\url{http://popstats.unhcr.org/en/overview})
}
\usage{
unhcr_popstats_2017
}
\description{
The dataset contains data about UNHCR's populations of concern for the year 2017.
}
\keyword{datasets}