library(plotly)
library(crosstalk)
sd <- SharedData$new(txhousing, ~city)
base <- plot_ly(sd, color = I("black")) %>%
group_by(city)
p1 <- base %>%
summarise(has = sum(is.na(median))) %>%
filter(has > 0) %>%
arrange(has) %>%
add_bars(x = ~has, y = ~factor(city, levels = city), hoverinfo = "x") %>%
layout(
barmode = "overlay",
xaxis = list(title = "Number of months missing"),
yaxis = list(title = "")
)
p2 <- base %>%
add_lines(x = ~date, y = ~median, alpha = 0.3) %>%
layout(xaxis = list(title = ""))
subplot(p1, p2, titleX = TRUE, widths = c(0.3, 0.7)) %>%
layout(margin = list(l = 120)) %>%
hide_legend() %>%
highlight(on = "plotly_click", off = NULL, color = "red")
# TODO: provide a way to loop through possible selections...
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.