ggiraph (version 0.4.4)

geom_vline_interactive: Vertical interactive reference line

Description

The geometry is based on geom_vline. See the documentation for those functions for more details.

Usage

geom_vline_interactive(mapping = NULL, data = NULL, ..., xintercept,
  na.rm = FALSE, show.legend = NA)

Arguments

mapping

The aesthetic mapping, see geom_point.

data

A data frame, see geom_point.

...

other arguments passed on to layer. See geom_point.

xintercept

controls the position of the line

na.rm
show.legend

See Also

ggiraph

Examples

Run this code
# NOT RUN {
# add interactive reference lines to a ggplot -------
library(ggplot2)

if (requireNamespace("dplyr", quietly = TRUE)) {

  g1 <- ggplot(diamonds, aes(carat)) +
    geom_histogram()

  gg_vline1 <- g1 + geom_vline_interactive(
    aes(xintercept = mean(carat),
        tooltip = round(mean(carat), 2),
        data_id = carat))
  ggiraph(code = print(gg_vline1))
}

dataset <- data.frame(x = rnorm(100))

dataset$clickjs <- rep(paste0("alert(\"",
                              round(mean(dataset$x), 2), "\")"), 100)

g2 <- ggplot(dataset, aes(x)) +
  geom_density(fill = "#000000", alpha = 0.7)
gg_vline2 <- g2 + geom_vline_interactive(
  aes(xintercept = mean(x), tooltip = round(mean(x), 2),
      data_id = x, onclick = clickjs), color = "white")

ggiraph(code = print(gg_vline2),
        hover_css = "cursor:pointer;fill:orange;stroke:orange;")
# }

Run the code above in your browser using DataCamp Workspace