library(ggiraph)
library(ggplot2)
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() +
theme_minimal()
x <- girafe(
ggobj = gg,
options = list(
opts_zoom(max = 5),
opts_selection(only_shiny = FALSE),
opts_toolbar(position = "top")
)
)
if (interactive()) print(x)
# Hide lasso selection tools (useful in Shiny when selections
# are controlled by other app interactions)
x <- girafe(
ggobj = gg,
options = list(
opts_zoom(max = 5),
opts_selection(only_shiny = FALSE),
opts_toolbar(
position = "top",
hidden = c("lasso_select", "lasso_deselect")
)
)
)
if (interactive()) print(x)
# Keep only zoom/pan and reset, hide rectangular zoom
x <- girafe(
ggobj = gg,
options = list(
opts_zoom(max = 5),
opts_selection(only_shiny = FALSE),
opts_toolbar(
position = "top",
hidden = c("selection", "zoom_rect", "saveaspng")
)
)
)
if (interactive()) print(x)
Run the code above in your browser using DataLab