Long format is helpful in ggplot2 plots.

kde2d_tidy(kde2d_output)

Arguments

kde2d_output

Ouput of MASS:kde2d output.

Examples

library("MASS") temp <- MASS::kde2d(x = runif(100, 0, 1) , y = runif(100, 0, 5) , n = 500 ) str(temp)
#> List of 3 #> $ x: num [1:500] 0.0136 0.0156 0.0175 0.0194 0.0214 ... #> $ y: num [1:500] 0.063 0.0728 0.0826 0.0924 0.1022 ... #> $ z: num [1:500, 1:500] 0.0915 0.0926 0.0936 0.0946 0.0957 ...
kde2d_tidy(temp)
#> x y z #> 1: 0.01362493 0.06303505 0.09151393 #> 2: 0.01556276 0.06303505 0.09255965 #> 3: 0.01750058 0.06303505 0.09360108 #> 4: 0.01943841 0.06303505 0.09463786 #> 5: 0.02137623 0.06303505 0.09566961 #> --- #> 249996: 0.97284868 4.95311226 0.06013776 #> 249997: 0.97478650 4.95311226 0.05937021 #> 249998: 0.97672433 4.95311226 0.05860426 #> 249999: 0.97866216 4.95311226 0.05784009 #> 250000: 0.98059998 4.95311226 0.05707791