I want to highlight the metric mean and median in Histogram plot using vertical lines. red to denote mean and blue to denote median. I am able to draw tow different kines however unable to order the color codes as per metrics.
I have created a dataframe d which I pass to my ggplot geom_vline. The dataframe contains metric calculation of mean and median and the desired color codes.
d = data.frame(metric = c(
mean(titanic_merge_clean$Age, na.rm = TRUE),
median(titanic_merge_clean$Age, na.rm = TRUE) ),
colr = c("red", "blue"))
titanic_merge_clean %>%
ggplot(aes(x = Age)) +
geom_histogram() +
geom_vline(data = d, aes(xintercept = metric,
color = colr))
dataframe d which is passed to ggplot geom_vline
Following is what d looks like:
In the resulting ggplot histogram above ordering of lines have reversed. The red is indicating median and blue is indicating mean.: