[R] how to overlay 2d pdf atop scatter plot using ggplot2

Big Floppy Dog bigfloppydog at gmail.com
Sun Oct 8 16:30:30 CEST 2017

Note: I have posted this on SO also but while the question has been
upvoted, there has been no answer yet.


Apologies for those who have seen it there also but I thought that this
list of experts may have someone who knows the answer.

I have the following example code:

xx <- data.frame(rmvt(100, df = c(13, 13)))
ggplot(data = xx,  aes(x = X1, y= X2)) + geom_point() + geom_density2d()

It yields a scatterplot of X2 against X1 and a KDE contour plot of the
density (as it should).

My question is: is it possible to change the contour plot to display
the contours

of a two-dimensional density function (say dmvt), using ggplot2?

The remaining figures in my document are in ggplot2 and therefore I
am looking for a ggplot2 solution.

Thanks in advance!


	[[alternative HTML version deleted]]

More information about the R-help mailing list