library(ggplot2)
library(ggiraph)
## the data
dataset = mtcars
dataset$label = row.names(mtcars)
dataset$tooltip = paste0( "cyl: ", dataset$cyl, "<br/>",
"gear: ", dataset$gear, "<br/>",
"carb: ", dataset$carb)
## the plot
gg_text = ggplot(dataset,
aes(x = mpg, y = wt, label = label,
color = qsec,
tooltip = tooltip, data_id = label)) +
geom_text_interactive(check_overlap = TRUE) +
coord_cartesian(xlim = c(0,50))
## display the plot
x <- girafe(ggobj = gg_text)
x <- girafe_options(x = x,
opts_hover(css = "fill:#FF4C3B;font-style:italic;") )
if( interactive() ) print(x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.