apexcharter/inst/examples/quick-apex.R

103 lines
2.8 KiB
R
Raw Normal View History

2019-02-14 16:37:40 +01:00
# ------------------------------------------------------------------------
#
# Title : Quick ApexCharts Examples
# By : Victor
# Date : 2019-02-14
#
# ------------------------------------------------------------------------
# Packages ----------------------------------------------------------------
library(apexcharter)
library(ggplot2)
library(dplyr)
# Bar & Column ------------------------------------------------------------
data("mpg")
n_manufac <- count(mpg, manufacturer)
apex(data = n_manufac, type = "bar", mapping = aes(x = manufacturer, y = n))
apex(data = n_manufac, type = "column", mapping = aes(x = manufacturer, y = n))
n_manufac_year <- count(mpg, manufacturer, year)
apex(data = n_manufac_year, type = "bar", mapping = aes(x = manufacturer, y = n, fill = year))
apex(data = n_manufac_year, type = "column", mapping = aes(x = manufacturer, y = n, fill = year))
# Line, Spline & Area -----------------------------------------------------
data("economics")
economics <- tail(economics, 100)
economics_long <- economics_long %>%
group_by(variable) %>%
slice(1:100)
apex(data = economics, type = "line", mapping = aes(x = date, y = uempmed))
apex(data = economics, type = "spline", mapping = aes(x = date, y = uempmed))
apex(data = economics, type = "area", mapping = aes(x = date, y = uempmed))
apex(data = economics_long, type = "line", mapping = aes(x = date, y = value01, fill = variable))
apex(data = economics_long, type = "spline", mapping = aes(x = date, y = value01, fill = variable))
apex(data = economics_long, type = "area", mapping = aes(x = date, y = value01, fill = variable))
2019-02-14 17:40:03 +01:00
# Scatter & Bubble --------------------------------------------------------
apex(data = iris, type = "scatter", mapping = aes(x = Sepal.Length, y = Sepal.Width, fill = Species)) %>%
ax_yaxis(min = min(iris$Sepal.Width))
2019-02-14 18:33:28 +01:00
apex(data = iris, type = "scatter", mapping = aes(x = Sepal.Length, y = Sepal.Width, fill = Species, z = Petal.Length)) %>%
ax_yaxis(min = min(iris$Sepal.Width))
apex(data = mtcars, type = "scatter", mapping = aes(x = wt, y = mpg))
apex(data = mtcars, type = "scatter", mapping = aes(x = wt, y = mpg, fill = cyl))
apex(data = mtcars, type = "scatter", mapping = aes(x = wt, y = mpg, z = scales::rescale(qsec)))
# Pie ---------------------------------------------------------------------
fruits <- data.frame(
name = c('Apples', 'Oranges', 'Bananas', 'Berries'),
value = c(44, 55, 67, 83)
)
apex(data = fruits, type = "pie", mapping = aes(x = name, y = value))
# Radial ------------------------------------------------------------------
apex(data = NULL, type = "radialBar", mapping = aes(x = "My value", y = 65))
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))
2019-02-14 17:40:03 +01:00