I have some data I would like to visualize and I am able to make the chart on the left, but I would like to be able to provide more information to the viewer by implementing features like those in the image to the right: shaded based on predefined ranges, and percentage of area in each range.
I recognize that this question is similar to these two answers, however I don't understand densities enough to get the dataframe in the correct format:
Here is the code that replicates my example.
If you can, please use dplyr in your response.
Thank you in advance.
library(dplyr)
library(ggplot2)
options(scipen = 999)
#Get percentages
diamonds%>%
mutate(Cut = cut,
Prices = cut(price,
breaks=c(0,2499,4999, 19000),
include.lowest=T, dig.lab=10))%>%
group_by(Cut, Prices)%>%
summarise(Count = n())%>%
group_by(Cut)%>%
mutate(Pct = round(Count/sum(Count), 2))%>%
ungroup()
#Plot
ggplot(diamonds, aes(x=price))+
geom_density(fill="grey50")+
facet_grid(cut~.)+
geom_vline(xintercept = c(2500,5000))+
theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank())