Plot: 2D distribution plots
By tholscla on Sun, 11/03/2013 - 12:04Here are 4 quick ways to plot 2D distributions. See here for more color options.
library(MASS) #kde2d() and mvrnorm()
VV=matrix(c(10,8,8,10),2,2)
coef=mvrnorm(10000,c(2,10),VV)
par(mfrow=c(2,2), mar=c(4,4,1,1))
### 1
plot(coef[,1],coef[,2])
### 2
contour(kde2d(coef[,1],coef[,2]))
### 3
persp(kde2d(coef[,1],coef[,2]))
### 4
image(kde2d(coef[,1],coef[,2], n = 100))
box()