When I run the below code, a density plot and histogram will be created. I've added two vertical line to show mean and median. I want to display a legend ("Mean" with dotted red and "Median" with green color) at the top-right corner of the plot. You can run this code as the df is already available in R-studio.
ggplot(USArrests,aes(x=Murder)) +
geom_histogram(aes(y=..density..),binwidth=.5,col="black",fill="white") +
geom_density(alpha=.2,fill="coral") +
geom_vline(aes(xintercept=mean(Murder,na.rm=T)),color="red",linetype="dashed",size=1) +
geom_vline(aes(xintercept=median(Murder,na.rm=T)),color="green",size=1)
My question is shall I use theme() or something else to display legend in my plot?