Skip to content

Commit 4766545

Browse files
committed
exclude NA data from traces
1 parent 2581b0e commit 4766545

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

R/trace_generation.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
#' @return list representing a layer, with corresponding aesthetics, ranges, and groups.
66
#' @export
77
layer2traces <- function(l, d, misc) {
8+
not.na <- function(df){
9+
na.mat <- sapply(df, is.na)
10+
to.exclude <- apply(na.mat, 1, any)
11+
df[!to.exclude, ]
12+
}
813
g <- list(geom=l$geom$objname,
9-
data=d,
10-
prestats.data=misc$prestats.data)
14+
data=not.na(d),
15+
prestats.data=not.na(misc$prestats.data))
1116
## needed for when group, etc. is an expression.
1217
g$aes <- sapply(l$mapping, function(k) as.character(as.expression(k)))
1318
# Partial conversion for geom_violin (Plotly does not offer KDE yet)
@@ -61,7 +66,7 @@ layer2traces <- function(l, d, misc) {
6166
}
6267

6368
# For some plot types, we overwrite `data` with `prestats.data`.
64-
pdata.vec <- misc$prestats.data[[a]]
69+
pdata.vec <- g$prestats.data[[a]]
6570
if (inherits(data.vec, "POSIXt")) {
6671
## Re-create dates from nb seconds
6772
data.vec <- try(strftime(as.POSIXlt(g$data[[a]], origin=the.epoch),

tests/testthat.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ save_outputs <- function(gg, name, ignore_ggplot=FALSE) {
33
print(paste("running", name))
44
}
55
test_check("plotly")
6+

0 commit comments

Comments
 (0)