I'm creating a ggplotly for a dataframe that's very similar to diamonds
. Here's what I have so far:
ggplotly(ggplot(diamonds, aes(depth, colour = cut)) +
geom_density() +
xlim(55, 70))
It creates the following:
When you hover over the trace it shows: depth, cut, and density. I want to also show the clarity so I added the following:
ggplotly(ggplot(diamonds, aes(depth, text = paste("Clarity: ", clarity), colour = cut)) +
geom_density() +
xlim(55, 70))
That command creates the following:
When I hover of the curve it shows depth, Clarity, cut, and density. That's what I want. However, how do I keep the density as one curve like how it was in the first plot I created instead of multiple curves?
Does this work? Set the alpha of the extra lines to 0 (so they become transparent. Using geom_line as geom_density uses alpha for fill only. (system problems prevent testing)
ggplotly(
ggplot(diamonds, aes(depth, colour = cut)) +
geom_density() +
geom_line(aes(text = paste("Clarity: ", clarity)), stat="density", alpha=0) +
xlim(55, 70)
)