Skip to contents

geom_sdv_logos() and its siblings with ggiraph's interactivity: map tooltip, data_id or onclick, then render with ggiraph::girafe(). Each returns two layers: the images, and an invisible interactive point over each that takes the hover.

Usage

geom_sdv_logos_interactive(
  mapping = NULL,
  data = NULL,
  ...,
  league,
  hover_size = 8,
  max_px = 160,
  id_system = "auto",
  strict = FALSE,
  inherit.aes = TRUE
)

geom_sdv_wordmarks_interactive(
  mapping = NULL,
  data = NULL,
  ...,
  league,
  hover_size = 8,
  max_px = 160,
  id_system = "auto",
  strict = FALSE,
  inherit.aes = TRUE
)

geom_sdv_headshots_interactive(
  mapping = NULL,
  data = NULL,
  ...,
  league,
  hover_size = 8,
  max_px = 160,
  id_system = "espn",
  inherit.aes = TRUE
)

Arguments

mapping

Set of aesthetic mappings created by aes(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).

...

Passed to the image layer (width, height, alpha, ...).

league

A league key from sdv_leagues(). Required: one abbreviation means different teams in different leagues.

hover_size

The size of the invisible hover target, in ggplot2 point size.

max_px

The longest side, in pixels, of each image embedded in the page. ggiraph writes every image into the widget, and a source logo (500 px) or headshot is 20-300 KB, so 30 of them make a page of megabytes; 160 px stays sharp at the size these geoms draw. NULL embeds the source.

id_system

For headshots, as in sdv_headshot_url().

strict

If TRUE, a value that does not resolve is an error; otherwise it becomes NA with one warning per call.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. annotation_borders().

Value

A list of two ggplot2 layers, to add with +.

Examples

# \donttest{
if (requireNamespace("ggiraph", quietly = TRUE)) {
  library(ggplot2)
  d <- data.frame(x = 1:3, y = c(2, 3, 1), team = c("KC", "BUF", "BAL"))
  p <- ggplot(d, aes(x, y)) +
    geom_sdv_logos_interactive(
      aes(team = team, tooltip = team, data_id = team),
      league = "nfl", width = 0.1
    )
  ggiraph::girafe(ggobj = p)
}
# }