library("ggplot2")
library("ggiraph")
gg_th <- theme(axis.ticks = element_line(colour = "gray90"),
    panel.grid.major = element_line(colour = "gray90"),
    panel.grid.minor = element_line(colour = "transparent"),
    panel.background = element_rect(fill = "transparent"))

Overview

The ggiraph attempts to produce interactive ggplot2 graphics. It extends ggplot2 with new geom functions:

You can install the package via

install.packages("ggiraph")

Example: Clickable links

Perhaps the most interesting feature is that you can add links to points

data(USArrests, package = "datasets")
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
crimes$onclick <- sprintf(
  "window.open(\"%s%s\")",
  "http://en.wikipedia.org/wiki/",
  as.character(crimes$state)
)

gg_point_3 <- ggplot(crimes, aes(x = Murder, y = Assault,
                                 size = UrbanPop, colour = Rape)) +
  geom_point_interactive(
    aes(data_id = state, tooltip = state, onclick = onclick)) +
  scale_colour_gradient(low = "#999999", high = "#FF3333") + gg_th

ggiraph(code = print(gg_point_3),
        hover_css = "fill-opacity:.3;cursor:pointer;")

Links



jr-packages/jrAutomate documentation built on Dec. 14, 2019, 6:35 p.m.