I would like to add hover text annotations to a dot plot in R. But ggplotly doesn't seem to work with geom_dotplot.
I would like the final dotplot to look like something this:
df <- data.frame(year = c("2000", "2005", "2005", "2010", "2010", "2010"), name = c("George", "Michael", "Bob", "James", "Will", "Fabrizio"))
ggplot(df, aes(x = year)) + geom_dotplot(, stackratio = 1, fill = "darkgreen", stackgroups = TRUE)
But then I want the "name" data to appear when you hover on a given dot.
The following code works with other graphs (geom_point, for example), but with geom_dotplot the look changes entirely, and the hover text doesn't work:
ggplotly(ggplot(df, aes(x = year, text = paste(name))) + geom_dotplot(, stackratio = 1, fill = "darkgreen", stackgroups = TRUE, binpositions="all"), tooltip = "text")
Any help with this would be much appreciated! Thank you.
Reed
According to the documentation it seems not possible to create hover texts with
geom_dotplot
inggplotly
. When you check this documenation, you can see that none of the options given hovers the labels. Even when usinglabel
ortext
in youraes
withtooltip
seems not working.As an option, maybe you want to use
fill
to show the names like this:Output: