library(gglite)
p = g2(mtcars, hp ~ mpg)
Interactions enable user-driven behaviors such as tooltips, brushing, and
highlighting. Use interact() to add them.
p |> interact('tooltip')
Highlight individual elements on hover.
pc = g2(mtcars, hp ~ mpg, color = ~ cyl)
pc |> interact('elementHighlight')
Highlight all elements sharing the same x value.
df = data.frame(
x = rep(c('A', 'B', 'C'), each = 2), y = c(3, 2, 5, 4, 1, 6),
color = rep(c('a', 'b'), 3)
)
pd = g2(df, y ~ x, color = ~ color) |>
mark_interval() |>
transform('dodgeX')
pd |> interact('elementHighlightByX')
pd |> interact('elementHighlightByColor')
Click to select individual elements.
pc |> interact('elementSelect')
Drag to brush and highlight a rectangular region.
p |> interact('brushHighlight')
Brush only along the x axis.
p |> interact('brushXHighlight')
Brush only along the y axis.
p |> interact('brushYHighlight')
Drag to filter the visible data.
p |> interact('brushFilter')
Click legend entries to filter data.
p_iris = g2(iris, Sepal.Length ~ Sepal.Width, color = ~ Species)
p_iris |> interact('legendFilter')
Hover over legend entries to highlight.
p_iris |> interact('legendHighlight')
You can combine several interactions.
p_iris |>
interact('tooltip') |>
interact('legendFilter') |>
interact('brushHighlight')