Adding summary stat such as mean, median, mode on ggplot

r
ggplot2

#1

This plot seems to showing vertical lines on histogram plot for price distibution of diamond data.
How can I add both median plus mean line on x axis using ggplot.


#2

Hello Ashish,

you need to add mean and median as columns in a copy of diamond dataset.
and then use the resulting dataframe to generate the histogram.

Next add the vline layer using the below code after the geom_histogram layer.

geom_vline(data=df, aes(xintercept = mean), colour=“black”) +
geom_vline(data=df, aes(xintercept = median), colour=“red”) +