library(MASS)
Sigma <- matrix(c(1,0.7,0.7,1),2,2)
Sigma
r=mvrnorm(n=1000, c(0,3), Sigma)
par(mfrow = c(2, 2))
#density plot
plot(density(r))
#kernel density estimate
bivn.kde <- kde2d(r[,1], r[,2], n = 50)
#perspective plot
persp(bivn.kde, phi = 45, theta = 30)
#contour plot
contour(bivn.kde)
#contour plot with image
image(bivn.kde,col = terrain.colors(100)); contour(bivn.kde, add = T)