Learn R Programming

RKorAPClient (version 0.5.9)

ggplotly: Experimental: Convert ggplot2 to plotly with hyperlinks to KorAP queries

Description

RKorAPClient::ggplotly converts a ggplot2::ggplot() object to a plotly object with hyperlinks from data points to corresponding KorAP queries. Warning: This function may be moved to a new package.

Usage

ggplotly(p = ggplot2::last_plot(), tooltip = c("x", "y", "colour", "url"), ...)

Arguments

p

a ggplot object.

tooltip

a character vector specifying which aesthetic mappings to show in the tooltip. If you want hyperlinks to KorAP queries you need to include "url" here.

...

Other arguments passed to plotly::ggplotly

Examples

Run this code
# NOT RUN {
library(ggplot2)
kco <- new("KorAPConnection", verbose=TRUE)
# }
# NOT RUN {
year <- (2003:2011)
# }
# NOT RUN {
condition <- c("textDomain = /Wirtschaft.*/", "textDomain != /Wirtschaft.*/")
# }
# NOT RUN {
g <- expand_grid(condition, year) %>%
  cbind(frequencyQuery(kco, "[tt/l=Heuschrecke]",
                       paste0(.$condition," & pubDate in ", .$year)))  %>%
  ipm() %>%
  ggplot(aes(year, ipm, fill = condition, color = condition)) +
  ##  theme_light(base_size = 20) +
  geom_freq_by_year_ci()
p <- ggplotly(g)
print(p)
## saveWidget(p, paste0(tmpdir(), "heuschrecke.html")


# }

Run the code above in your browser using DataLab