How to customize hover information in ggplotly object?
A cleaner way is to just add everything within the ggplot
environment, using aesthetics two times, in order to pass just the full, single object onto ggplotly()
:
p <- ggplot(mtcars, aes(label = gear, label2 = hp)) +
geom_point(aes(x = disp, y= am, color = as.factor(cyl)))
ggplotly(p)
You can include required variables in aes()
then use tooltip
to specify which 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"))