Description Usage Arguments Details Examples
Apply a function to each element of a vector and return a vector of plots
1 |
.x |
a list or atomic vector (see |
.f |
a function, formula, or atomic vector (see |
... |
additional arguments passed on to .f (see |
See map
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.