map2_plot: Map over multiple inputs simultaneously and return a vector...

Description Usage Arguments Details Examples

View source: R/tidy.R

Description

Map over multiple inputs simultaneously and return a vector of plots

Usage

1
2
3
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library(tidyr)
library(purrr)
library(plotly)
library(dplyr)

iris %>%
  nest(data = -Species) %>%
  mutate(
    mod = map(data, ~ lm(Sepal.Length ~ Sepal.Width, data = .x)),
    panel = map2_plot(data, mod, function(data, mod) {
      plot_ly(data = data, x = ~Sepal.Width, y = ~Sepal.Length,
        type = "scatter", mode = "markers", name = "data") %>%
        add_trace(data = data, x = ~Sepal.Width, y = ~predict(mod),
          mode = "lines", name = "lm")
    })) %>%
  trelliscope(name = "iris")

trelliscopejs documentation built on Feb. 1, 2021, 9:05 a.m.