4  Interactivity with ggiraph

Published

2025-08-29

The package ggiraph (Gohel and Skintzos (2025)) makes ggplot graphics interactive.

Example from here.

Hovering over the point shows the names of the cars.

library(ggplot2)
library(ggiraph)

dataset <- mtcars
dataset$carname <- row.names(mtcars)

gg <- ggplot(
  data = dataset,
  mapping = aes(
    x = wt, y = qsec, color = disp,
    tooltip = carname, data_id = carname
  )
) +
  geom_point_interactive()

girafe(ggobj = gg)

Don’t forget to call the girafe function otherwise it will be a plain ggplot image and not an interactive plot.