# NOT RUN {
library(ks)
dat <- replicate(2, rnorm(100))
k <- kde(dat)
td <- tidy(k)
td
library(ggplot2)
library(dplyr)
library(tidyr)
td %>%
pivot_wider(c(obs, estimate),
names_from = variable,
values_from = value
) %>%
ggplot(aes(x1, x2, fill = estimate)) +
geom_tile() +
theme_void()
# also works with 3 dimensions
dat3 <- replicate(3, rnorm(100))
k3 <- kde(dat3)
td3 <- tidy(k3)
td3
# }
Run the code above in your browser using DataLab