crosstalk: that’s what shiny is based on - we will look into shiny laterplotly: interactive javascript graphics (maintained by Carson Sievert)leaflet: (RStudio) allows to make interactive maps. Has been picking up users and has developed a stable user base.ggvis: both static and interactive graphics, work on it has stalled … (Wickham)animint2: interactive, linked graphics with ggplot2 syntax (Toby Hocking)rCharts, rbokeh, gridSVG, epivizr, cranvas previous approaches to packages with interactive graphicsThe plotly package in R has two interfaces:
ggplot2 plots and adding interactive elementsPlotly creates interactive plots with javascript.
Not all ggplot2 geoms are supported in plotly, but when they are, they just work out of the box
plotly uses elements of crosstalk to provide additional interactivity, such as linked highlighting
txh_shared <- highlight_key(txhousing, ~year)
p <- ggplot(txh_shared, aes(month, median)) +
geom_line(aes(group = year)) +
geom_smooth(data = txhousing, method = "gam") +
scale_x_continuous("", breaks=seq(1, 12, 1),
labels=c("J", "F", "M", "A", "M", "J",
"J", "A", "S", "O", "N", "D")) +
scale_y_continuous("Median price ('00,000)",
breaks = seq(0,300000,100000),
labels = seq(0,3,1)) +
facet_wrap(~ city)
gg <- ggplotly(p, height = 750, width = 900) %>%
plotly::layout(title = "Click on a line to highlight a year")library(tsibble) # install.packages("tsibble")
library(tsibbletalk) # install.packages("tsibbletalk")
library(feasts) # install.packages("feasts")
tourism_shared <- tourism |>
as_shared_tsibble(spec = (State / Region) * Purpose)
tourism_feat <- tourism_shared |>
features(Trips, feat_stl)
p1 <- tourism_shared |>
ggplot(aes(x = Quarter, y = Trips)) +
geom_line(aes(group = Region), alpha = 0.5) +
facet_wrap(~ Purpose, scales = "free_y") + theme_helvetica
p2 <- tourism_feat |>
ggplot(aes(x = trend_strength, y = seasonal_strength_year)) +
geom_point(aes(group = Region)) +
xlab("trend") + ylab("season") + theme_helveticaThe shared data objects from crosstalk make linking between plots easier!
highlight allows to make modifications in how highlighted values are presented in plotly. Read through the parameter details in ?highlight.dynamic is set to FALSE by default. Turn it to TRUE. What is the effect?
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.