[R] Adding 95% contours around scatterplot points with ggplot2

2013-01-28 Thread Nathan Miller
Hi all, I have been looking for means of add a contour around some points in a scatterplot as a means of representing the center of density for of the data. I'm imagining something like a 95% confidence estimate drawn around the data. So far I have found some code for drawing polygons around the

Re: [R] Adding 95% contours around scatterplot points with ggplot2

2013-01-28 Thread 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 natemille...@gmail.com wrote: Hi all, I have been looking for means of add a contour around some points in a scatterplot as a means of

Re: [R] Adding 95% contours around scatterplot points with ggplot2

2013-01-28 Thread Nathan Miller
Thanks Ista, I have played a bit with stat_density2d as well. It doesn't completely capture what I am looking for and ends up being quite busy at the same time. I'm looking for a way of helping those looking that the figure to see the broad patterns of where in the x/y space the data from

Re: [R] Adding 95% contours around scatterplot points with ggplot2

2013-01-28 Thread Ista Zahn
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,

Re: [R] Adding 95% contours around scatterplot points with ggplot2

2013-01-28 Thread Nathan Miller
Hi Ista, Thanks. That does look pretty nice and I hadn't realized that was possible. Do you know how to extract information regarding those curves? I'd like to be able to report something about what portion of the data they encompass or really any other feature about them in a figure legend. I'll

Re: [R] Adding 95% contours around scatterplot points with ggplot2

2013-01-28 Thread Ista Zahn
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 natemille...@gmail.com wrote: Hi Ista, Thanks. That does look pretty