added slope charts
This commit is contained in:
parent
7e4189366e
commit
b313b45989
20
R/apex.R
20
R/apex.R
|
@ -14,7 +14,7 @@
|
|||
#' `"pie"`, `"donut"`,
|
||||
#' `"radialBar"`, `"radar"`, `"scatter"`,
|
||||
#' `"heatmap"`, `"treemap"`,
|
||||
#' `"timeline"` and `"dumbbell"`.
|
||||
#' `"timeline"`, `"dumbbell"` and `"slope"`.
|
||||
#' @param ... Other arguments passed on to methods. Not currently used.
|
||||
#' @param synchronize Give a common id to charts to synchronize them (tooltip and zoom).
|
||||
#' @param serie_name Name for the serie displayed in tooltip,
|
||||
|
@ -44,7 +44,7 @@ apex <- function(data, mapping,
|
|||
choices = c(
|
||||
"column", "bar",
|
||||
"rangeBar", "dumbbell",
|
||||
"line", "spline", "step",
|
||||
"line", "spline", "step", "slope",
|
||||
"area", "area-spline", "area-step",
|
||||
"rangeArea",
|
||||
"pie", "donut",
|
||||
|
@ -69,7 +69,7 @@ apex <- function(data, mapping,
|
|||
type <- "bubble"
|
||||
}
|
||||
mapdata <- lapply(mapping, rlang::eval_tidy, data = data)
|
||||
type_no_compute <- c("candlestick", "boxplot", "timeline", "heatmap", "rangeArea", "rangeBar", "dumbbell")
|
||||
type_no_compute <- c("candlestick", "boxplot", "timeline", "heatmap", "rangeArea", "rangeBar", "dumbbell", "slope")
|
||||
if (is.null(mapdata$y) & !type %in% type_no_compute) {
|
||||
mapdata <- compute_count(mapdata)
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ make_series <- function(mapdata, mapping, type = NULL, serie_name = NULL, force_
|
|||
)))
|
||||
if (is_grouped(mapping)) {
|
||||
mapdata <- rename_aes(mapdata)
|
||||
len_grp <- tapply(mapdata$group, mapdata$group, length)
|
||||
len_grp <- tapply(as.character(mapdata$group), as.character(mapdata$group), length)
|
||||
if (length(unique(len_grp)) > 1 & !isTRUE(type %in% c("scatter", "bubble"))) {
|
||||
warning("apex: all groups must have same length! You can use `tidyr::complete` for this.")
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ list1 <- function(x) {
|
|||
correct_type <- function(type) {
|
||||
if (isTRUE(type %in% c("column"))) {
|
||||
"bar"
|
||||
} else if (isTRUE(type %in% c("spline", "step"))) {
|
||||
} else if (isTRUE(type %in% c("spline", "step", "slope"))) {
|
||||
"line"
|
||||
} else if (isTRUE(type %in% c("area-spline", "area-step"))) {
|
||||
"area"
|
||||
|
@ -344,6 +344,7 @@ choose_config <- function(type, mapdata) {
|
|||
"timeline" = config_timeline(),
|
||||
"candlestick" = config_candlestick(),
|
||||
"boxplot" = config_boxplot(horizontal = box_horiz),
|
||||
"slope" = config_slope(),
|
||||
list()
|
||||
)
|
||||
}
|
||||
|
@ -464,3 +465,12 @@ config_boxplot <- function(horizontal = FALSE) {
|
|||
)
|
||||
}
|
||||
|
||||
config_slope <- function() {
|
||||
list(
|
||||
plotOptions = list(
|
||||
line = list(
|
||||
isSlopeChart = TRUE
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ a \code{data.frame}, it will be coerced to with \code{as.data.frame}.}
|
|||
\code{"pie"}, \code{"donut"},
|
||||
\code{"radialBar"}, \code{"radar"}, \code{"scatter"},
|
||||
\code{"heatmap"}, \code{"treemap"},
|
||||
\code{"timeline"} and \code{"dumbbell"}.}
|
||||
\code{"timeline"}, \code{"dumbbell"} and \code{"slope"}.}
|
||||
|
||||
\item{...}{Other arguments passed on to methods. Not currently used.}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"apexcharts": "^3.48.0",
|
||||
"apexcharts": "^3.49.1",
|
||||
"d3-format": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -371,9 +371,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/apexcharts": {
|
||||
"version": "3.48.0",
|
||||
"resolved": "https://registry.npmjs.org/apexcharts/-/apexcharts-3.48.0.tgz",
|
||||
"integrity": "sha512-Lhpj1Ij6lKlrUke8gf+P+SE6uGUn+Pe1TnCJ+zqrY0YMvbqM3LMb1lY+eybbTczUyk0RmMZomlTa2NgX2EUs4Q==",
|
||||
"version": "3.49.1",
|
||||
"resolved": "https://registry.npmjs.org/apexcharts/-/apexcharts-3.49.1.tgz",
|
||||
"integrity": "sha512-MqGtlq/KQuO8j0BBsUJYlRG8VBctKwYdwuBtajHgHTmSgUU3Oai+8oYN/rKCXwXzrUlYA+GiMgotAIbXY2BCGw==",
|
||||
"dependencies": {
|
||||
"@yr/monotone-cubic-spline": "^1.0.3",
|
||||
"svg.draggable.js": "^2.2.2",
|
||||
|
@ -2030,9 +2030,9 @@
|
|||
"requires": {}
|
||||
},
|
||||
"apexcharts": {
|
||||
"version": "3.48.0",
|
||||
"resolved": "https://registry.npmjs.org/apexcharts/-/apexcharts-3.48.0.tgz",
|
||||
"integrity": "sha512-Lhpj1Ij6lKlrUke8gf+P+SE6uGUn+Pe1TnCJ+zqrY0YMvbqM3LMb1lY+eybbTczUyk0RmMZomlTa2NgX2EUs4Q==",
|
||||
"version": "3.49.1",
|
||||
"resolved": "https://registry.npmjs.org/apexcharts/-/apexcharts-3.49.1.tgz",
|
||||
"integrity": "sha512-MqGtlq/KQuO8j0BBsUJYlRG8VBctKwYdwuBtajHgHTmSgUU3Oai+8oYN/rKCXwXzrUlYA+GiMgotAIbXY2BCGw==",
|
||||
"requires": {
|
||||
"@yr/monotone-cubic-spline": "^1.0.3",
|
||||
"svg.draggable.js": "^2.2.2",
|
||||
|
|
|
@ -336,3 +336,26 @@ apex(life_expec, aes(country, x = `1972`, xend = `2007`), type = "dumbbell") %>%
|
|||
)
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Slope charts
|
||||
|
||||
Create a slope chart with:
|
||||
|
||||
```{r slope}
|
||||
data("life_expec", package = "apexcharter")
|
||||
|
||||
apex(
|
||||
life_expec_long,
|
||||
mapping = aes(x = as.character(year), y = lifeExp, fill = country),
|
||||
type = "slope"
|
||||
) %>%
|
||||
ax_colors("#112466") %>%
|
||||
ax_labs(
|
||||
title = "Life expectancy : 1972 vs. 2007",
|
||||
subtitle = "Data from Gapminder dataset",
|
||||
x = "Life expectancy at birth, in years"
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue