apex: remove NAs in scatter chart (bis)
This commit is contained in:
parent
53e7addd8b
commit
af5670a0b0
24
R/apex.R
24
R/apex.R
|
@ -31,6 +31,7 @@
|
||||||
#'
|
#'
|
||||||
#' @importFrom rlang eval_tidy as_label
|
#' @importFrom rlang eval_tidy as_label
|
||||||
#' @importFrom utils modifyList
|
#' @importFrom utils modifyList
|
||||||
|
#' @importFrom stats complete.cases
|
||||||
#'
|
#'
|
||||||
#' @example examples/apex.R
|
#' @example examples/apex.R
|
||||||
apex <- function(data, mapping, type = "column", ...,
|
apex <- function(data, mapping, type = "column", ...,
|
||||||
|
@ -43,11 +44,16 @@ apex <- function(data, mapping, type = "column", ...,
|
||||||
type <- match.arg(
|
type <- match.arg(
|
||||||
arg = type,
|
arg = type,
|
||||||
choices = c(
|
choices = c(
|
||||||
"column", "bar", "line", "area", "spline", "step",
|
"column", "bar",
|
||||||
"area-spline", "area-step",
|
"line", "spline", "step",
|
||||||
"pie", "donut", "radialBar", "radar",
|
"area", "area-spline", "area-step",
|
||||||
"scatter", "heatmap",
|
"pie", "donut",
|
||||||
"timeline", "candlestick"
|
"radialBar",
|
||||||
|
"radar",
|
||||||
|
"scatter", "bubble",
|
||||||
|
"heatmap",
|
||||||
|
"timeline",
|
||||||
|
"candlestick"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
data <- as.data.frame(data)
|
data <- as.data.frame(data)
|
||||||
|
@ -118,6 +124,14 @@ make_series <- function(mapdata, mapping, type = NULL, serie_name = NULL) {
|
||||||
series <- parse_timeline_data(mapdata)
|
series <- parse_timeline_data(mapdata)
|
||||||
} else {
|
} else {
|
||||||
mapdata <- as.data.frame(mapdata, stringsAsFactors = FALSE)
|
mapdata <- as.data.frame(mapdata, stringsAsFactors = FALSE)
|
||||||
|
if (isTRUE(type %in% c("scatter", "bubble"))) {
|
||||||
|
complete <- complete.cases(mapdata[c("x", "y")])
|
||||||
|
n_missing <- sum(!complete)
|
||||||
|
if (n_missing > 0) {
|
||||||
|
mapdata <- mapdata[complete, ]
|
||||||
|
warning(sprintf("apex: Removed %s rows containing missing values", n_missing), call. = FALSE)
|
||||||
|
}
|
||||||
|
}
|
||||||
if (is.character(mapdata$x))
|
if (is.character(mapdata$x))
|
||||||
mapdata$x[is.na(mapdata$x)] <- "NA"
|
mapdata$x[is.na(mapdata$x)] <- "NA"
|
||||||
x_order <- unique(mapdata$x)
|
x_order <- unique(mapdata$x)
|
||||||
|
|
Loading…
Reference in New Issue