Chapter 16 Miscellaneous: interactive plots using plotly()

The plotly() library contains the function ggplotly(), which translates your ggplot code into an interactive plotly object in one line of code.

You can click on the species in the legend to add/remove species. You can also see values while hovering over points.

library(plotly)
p <- ggplot(penguins, aes(x = bill_length_mm, y = bill_depth_mm,
    colour = species, shape = species)) + geom_point(size = 6,
    alpha = 0.6)
# convert to a plotly object!
ggplotly(p)