Geom Density 2d

[Solved] Geom Density 2d | Matlab - Code Explorer | yomemimo.com
Question : geom_density_2d

Answered by : excited-echidna-5uwyez8fui2n

set.seed(1001)
d <- data.frame(x=rnorm(1000),y=rnorm(1000))
getLevel <- function(x,y,prob=0.95) { kk <- MASS::kde2d(x,y) dx <- diff(kk$x[1:2]) dy <- diff(kk$y[1:2]) sz <- sort(kk$z) c1 <- cumsum(sz) * dx * dy approx(c1, sz, xout = 1 - prob)$y
}
L95 <- getLevel(d$x,d$y)
library(ggplot2); theme_set(theme_bw())
ggplot(d,aes(x,y)) + stat_density2d(geom="tile", aes(fill = ..density..), contour = FALSE)+ stat_density2d(colour="red",breaks=L95)

Source : https://stackoverflow.com/questions/23437000/how-to-plot-a-contour-line-showing-where-95-of-values-fall-within-in-r-and-in | Last Update : Thu, 13 Jan 22

Answers related to geom density 2d

Code Explorer Popular Question For Matlab