2

I've used ggplot2 (specifically geom_density2d)to create a contour plot of some data.

Can anyone direct me towards information of how the contours are calculated? For example, does the outer contour contain say 95% of the data points?

Many thanks,

Tom

  • 1
    `stat_density2d` uses `MASS::kde2d` for the kernel density estimate. That function returns density values on a grid and a contour plot is created from that. I would expect the contour lines to be arbitrary, i.e. not related to any specific probability values at all. – Roland Aug 28 '13 at 10:01
  • Thanks very much for your reply Roland. I've had a look at the kde2d function and can't get much further without having the referenced textbook for S, which I don't have access to. I would think there must be some underlying interpretation for the contour lines. They must relate to a certain density of the data. Below I've added a simplified version of my plot which describes the modeled cost effectiveness of antiviral stockpiling for pandemic prepareness. There is uncertainty in my results and I'm hoping to convey they using the contour lines. Any Thoughts are Much appreciated – user1896970 Aug 29 '13 at 02:51
  • library(ggplot2) Cost <- rnorm(100,100,5) # Cost DeathAv <- rnorm(100, 5, 1) # Deaths Averted CEA <- data.frame(DeathAv, Cost) Fig <- ggplot(CEA) + geom_density2d(aes(x=DeathAv, y=Cost)) Fig1 <- Fig + geom_point(aes(x=mean(DeathAv), y=mean(Cost))) + geom_text(aes(x=mean(DeathAv), y=mean(Cost)), label="Mean Cost Effectiveness", hjust = 1.5) Fig1 – user1896970 Aug 29 '13 at 02:57
  • The contour lines represent the probability distributions in 2-D, they are not arbitrary. It is quite straight forward to understand by reading this Wikipedia page: https://en.wikipedia.org/wiki/Contour_line. – Cris Jul 10 '19 at 14:57

0 Answers0