import the library and the dataset

library(ggplot2)
data(diamonds)

visualizing the distribution of diamond prices with density curves colored by clarity. It overlays a histogram with a density curve on the same axis.

histogram_density <- ggplot(diamonds,aes(x=price , fill = clarity , color = clarity))+
  geom_histogram(aes(y = ..density..),binwidth = 500,alpha = 0.5, position = 'identity')+
  geom_density(alpha=0.2,adjust=1.5)              
labs(
  title = "distribution of diamond prices with density curves by clarity",
  x = " price(USD)",
  y= "density")+
  theme_minimal()+
  scale_fill_brewer( palette = "Dark2")+
  scale_color_brewer( palette = "Dark2")
## NULL

display the histogram

print(histogram_density)
## Warning: The dot-dot notation (`..density..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(density)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.