Skip to content

Instantly share code, notes, and snippets.

@geotheory
Created February 11, 2022 16:08

Revisions

  1. geotheory created this gist Feb 11, 2022.
    17 changes: 17 additions & 0 deletions ggiraph-alt-text.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@

    library(ggplot2)
    library(ggiraph)

    data <- mtcars
    data$carname <- row.names(data)

    gg_point = ggplot(data = data) +
    geom_point_interactive(aes(x = wt, y = qsec, color = disp,
    tooltip = carname, data_id = carname)) +
    theme_minimal()

    g = girafe(ggobj = gg_point)

    g$x$html = stringr::str_replace(g$x$html, fixed('<svg '), '<svg alt="A scatterplot of mtcars, plotting wt against qsec. The graph suggests a low correlation between two normally-distributed variables" ')

    g