0

I have a set of data and I want to take a subset of it, then graph it using the geom_density function. When I filter the range from -3 to 3, the resulting graph is larger than 1. I would like to show the percentage of the data that is represented by a score of 0 within this range. Is there a way to do this with geom_density function?

score %>%
  filter(zscore <3, zscore  > -3) %>%
  ggplot(aes(x=zscore)) + 
  theme_bw() 

Image showing the density function going above 1

  • Are you asking how to create the subset or how to scale the y-axis to percent? It looks like you've figured out the subset part. This may help with percentages https://stackoverflow.com/a/44189916/3968093 – Jan Kislinger Mar 22 '21 at 13:55
  • I think there is a slight confusion here, as densities can easily reach values >1; try `plot(density(rnorm(1000, sd = 0.01)))`. The property of densities is that they integrate to 1, not max out at 1. – teunbrand Mar 22 '21 at 14:04
  • Thanks! I didn't realize that they integrate to 1, I thought it maxed out at 1. Appreciate the help! – dexter1988 Mar 22 '21 at 14:08

0 Answers0