Skip to content

Commit

Permalink
Fix kde2d for datasets with nonfinite values
Browse files Browse the repository at this point in the history
Using the method kde2d will no longer cause an error if x/y contain
non-finite values.
  • Loading branch information
lysogeny committed Feb 13, 2020
1 parent 7c6cb1d commit 0264094
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions R/geom_pointdensity.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,17 @@ StatPointdensity <- ggproto("StatPointdensity", Stat,

} else if (identical(method, "kde2d")) {

finites <- is.finite(data$x) & is.finite(data$y)
ddata <- data[finites,]
base.args <- list(
x = data$x,
y = data$y,
x = ddata$x,
y = ddata$y,
lims = c(scales$x$dimension(), scales$y$dimension()))
if (!is.element("n", names(method.args))) {
method.args["n"] <- 100
}
if (!is.element("h", names(method.args))) {
h <- c(MASS::bandwidth.nrd(data$x), MASS::bandwidth.nrd(data$y))
h <- c(MASS::bandwidth.nrd(ddata$x), MASS::bandwidth.nrd(ddata$y))
method.args$h <- h * adjust
}

Expand Down

0 comments on commit 0264094

Please sign in to comment.