library(MASS)
x <- rnorm(100)
y <- rnorm(100)
plot(x, y, ann=F, axes=F, col="grey")
box(col="grey")

rect(min(x), min(y), max(x), max(y), lty="dashed")
hull <- chull(x, y)
polygon(x[hull], y[hull])

plot of chunk unnamed-chunk-1

library(MASS)
library(ggplot2)
x <- rnorm(100)
y <- rnorm(100)
plot(x, y, ann=F, axes=F, col="grey")
box(col="grey")
#plot(duration, waiting, xlim = c(0.5,6), ylim = c(40,100))
f1 <- kde2d(x, y, n = 50, lims = c(-3, 3, -3, 3))
contour(f1, xlab = "x", levels = c(0.05), drawlabels=FALSE,
        ylab = "y", add=TRUE)

plot of chunk unnamed-chunk-2

df <- data.frame(cbind(x, y))
ggplot(df, aes(x, y)) + geom_point() + geom_contour(stat="density2d", breaks=0.05) + theme_bw()

plot of chunk unnamed-chunk-2