I need to add a mean line and the value of the mode for example to this kinds of plots:
I use this for calculate the number of bins:
bw <- diff(range(cars$lenght)) / (2 * IQR(cars$lenght) / length(cars$lenght)^(1/3))
And the plot:
ggplot(data=cars, aes(cars$lenght)) +
geom_histogram(aes(y =..density..),
col="red",
binwidth = bw,
fill="green",
alpha=1) +
geom_density(col=4) +
labs(title='Lenght Plot', x='Lenght', y='Times')
cars$lenght
168.8 168.8 171.2 176.6 176.6 177.3 192.7 192.7 192.7 178.2 176.8 176.8 176.8 176.8 189.0 189.0 193.8 197.0 141.1 155.9 158.8 157.3 157.3 157.3 157.3 157.3 157.3 157.3 174.6 173.2
Thanks in advance.