trelliscopejs (version 0.1.11)

map2_plot: Map over multiple inputs simultaneously and return a vector of plots

Description

Map over multiple inputs simultaneously and return a vector of plots

Usage

map2_plot(.x, .y, .f, ...)

pmap_plot(.l, .f, ...)

Arguments

.x, .y

Vectors of the same length. A vector of length 1 will be recycled.

.f

A function, formula, or atomic vector (see map2 for details)

...

additional arguments passed on to .f.

.l

A list of lists. The length of .l determines the number of arguments that .f will be called with. List names will be used if present.

Details

See map2

Examples

Run this code
# NOT RUN {
library(tidyr)
library(purrr)
library(rbokeh)
library(dplyr)

iris %>%
  nest(-Species) %>%
  mutate(
    mod = map(data, ~ lm(Sepal.Length ~ Sepal.Width, data = .x)),
    panel = map2_plot(data, mod, function(data, mod) {
      figure(xlab = "Sepal.Width", ylab = "Sepal.Length") %>%
        ly_points(data$Sepal.Width, data$Sepal.Length) %>%
        ly_abline(mod)
    })) %>%
  trelliscope(name = "iris")

iris %>%
  nest(-Species) %>%
  mutate(
    mod = map(data, ~ lm(Sepal.Length ~ Sepal.Width, data = .x)),
    panel = pmap_plot(list(data = data, mod = mod), function(data, mod) {
      figure(xlab = "Sepal.Width", ylab = "Sepal.Length") %>%
        ly_points(data$Sepal.Width, data$Sepal.Length) %>%
        ly_abline(mod)
    })) %>%
  trelliscope(name = "iris")
# }

Run the code above in your browser using DataCamp Workspace