0

I have a histogram with percentages on the Y axis:

    df <- data.frame(V1 = rnorm(100))
    ggplot(df, aes(x = V1)) +  
  geom_histogram(aes(y = 100*(..count..)/sum(..count..)))+geom_density()

I tried to add a density curve using geom_density() but it appears to be on the wrong scale for the percentages. How can I fix this?

curve

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213

1 Answers1

0

You can use ..density..

Code

df %>% 
  ggplot(aes(x = V1)) +  
  geom_histogram(aes(y = ..density..))+
  geom_density()

Output

enter image description here

Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32