9 Histograme - curbe de densitate

ggplot(data=weather, aes(x=temp))+
  geom_histogram(color='white', fill='tomato')
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 1 rows containing non-finite values (`stat_bin()`).
ggplot(data=weather, aes(x=temp))+
  geom_histogram(aes(y=after_stat(density)), color='white', fill='tomato')+
  geom_density(color='darkgreen',linetype=2, lwd=1, fill='yellow', alpha=0.4)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 1 rows containing non-finite values (`stat_bin()`).
## Warning: Removed 1 rows containing non-finite values (`stat_density()`).
mean(weather$temp, na.rm = TRUE)
## [1] 55.26039
sd(weather$temp, na.rm=TRUE)
## [1] 17.78785
ggplot(data=weather, aes(x=temp))+
  geom_histogram(aes(y=after_stat(density)), color='white', fill='tomato')+
  geom_density(color='darkgreen',linetype=2, lwd=1, fill='yellow', alpha=0.4) +
  stat_function(fun=dnorm, 
            args=list(
              mean = mean(weather$temp, na.rm = TRUE), 
              sd = sd(weather$temp, na.rm = TRUE)
              ),
            lwd=1.5, color='darkblue', linetype=5
    )
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 1 rows containing non-finite values (`stat_bin()`).
## Warning: Removed 1 rows containing non-finite values (`stat_density()`).
grafic <- ggplot(data=weather, aes(x=temp))+
  geom_histogram(aes(y=after_stat(density)), color='white', fill='tomato')+
  geom_density(color='darkgreen',linetype=2, lwd=1, fill='yellow', alpha=0.2) +
  stat_function(fun=dnorm, 
            args=list(
              mean = mean(weather$temp, na.rm = TRUE), 
              sd = sd(weather$temp, na.rm = TRUE)
              ),
            lwd=1, color='darkblue', linetype=5
    )
grafic
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 1 rows containing non-finite values (`stat_bin()`).
## Warning: Removed 1 rows containing non-finite values (`stat_density()`).