# NOT RUN {
library(dplyr)
library(tidyr)
library(purrr)
library(plotly)
library(gapminder)
# nest gapminder data by country
by_country <- gapminder %>%
nest(data = !one_of(c("country", "continent")))
# add in a plot column with map_plot
by_country <- by_country %>% mutate(
panel = map_plot(data, function(x) {
plot_ly(data = x, x = ~year, y = ~lifeExp,
type = "scatter", mode = "markers") %>%
layout(
xaxis = list(range = c(1948, 2011)),
yaxis = list(range = c(10, 95)))
}))
# plot it
by_country %>%
trelliscope("gapminder", nrow = 2, ncol = 7, width = 300)
# example using mpg data
ggplot2::mpg %>%
nest(data = !one_of(c("manufacturer", "class"))) %>%
mutate(panel = map_plot(data, function(x) {
plot_ly(data = x, x = ~hwy, y = ~cty,
type = "scatter", mode = "markers")
})) %>%
trelliscope(name = "city_vs_highway_mpg")
# }
Run the code above in your browser using DataCamp Workspace