R extract coordinates plotted by ggplot2::stat_density_2d

Viewed 1812

I am looking for the coordinates of contour lines produced by ggplot2::geom_density_2d.

I am after a list of (matrices of) x/y coordinates. One for each contour line.

This should be similar to what contourLines gives, but I was unable to get the desired result.

Here is some sample code from ?stat_density2d

 m <- ggplot(faithful, aes(x = eruptions, y = waiting)) +
  geom_point() +
  xlim(0.5, 6) +
  ylim(40, 110)
 m + geom_density_2d()
1 Answers
Related