Skip to content

Adding 95% contours around scatterplot points with ggplot2

6 messages · Nathan Miller, Ista Zahn

#
Hi Nathan,

This only fits some of your criteria, but have you looked at ?stat_density2d?

Best,
Ista
On Mon, Jan 28, 2013 at 12:53 PM, Nathan Miller <natemiller77 at gmail.com> wrote:
#
Hi Nate,

You can make it less busy using the bins argument. This is not
documented, except in the examples to stat_contour, but try

ggplot(data=data, aes(x, y, colour=(factor(level)), fill=level))+
	geom_point()+
	stat_density2d(bins=2)

HTH,
Ista
On Mon, Jan 28, 2013 at 2:43 PM, Nathan Miller <natemiller77 at gmail.com> wrote:
#
Hi Nate,

I infer from the stat_density2d documentation that the calculation is
carried out by the kde2d function in the MASS package. Refer to ?kde2d
for details.

Best,
Ista
On Mon, Jan 28, 2013 at 3:56 PM, Nathan Miller <natemiller77 at gmail.com> wrote: