How to set up hover information in a ggplotly object?

Is there a way to configure hoverinfo in a ggplotly object?

For instance,

p <- ggplot(mtcars, aes(x = disp, y= am, color = as.factor(cyl)))+geom_point()

ggplotly(p)

The guidance field contains three variables: disp, am, and factor (cyl). How to include more variables or exclude existing variables in the hover info field?

Thank!

+4
source share
1 answer

You can include the required variables in aes(), then use tooltipto indicate what should be displayed:

p <- ggplot(mtcars, aes(x = disp, y= am, color = as.factor(cyl), 
                        gear=gear, hp=hp))+geom_point()
ggplotly(p,tooltip = c("x", "gear", "hp"))
+5
source

Source: https://habr.com/ru/post/1660728/


All Articles