save_data: Compute and save layer datasets for a ggplot2 plot.

Description Usage Arguments Value Examples

Description

Compute and save layer datasets for a ggplot2 plot.

Usage

1
2
3

Arguments

ggplot2

plot

path

Existing directory in which to save plot datasets.

Value

save_data: (invisibly) a list that can be transformed to JSON to produce vega data spec.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
p1 <- ggplot(mtcars, aes(disp, cyl)) +
  geom_point()
str(plot_data(p1))

str(plot_data(p1 + geom_point(aes(y = cyl + 1))))

p2 <- p1 + geom_point(aes(displ * 61, cyl), data = mpg)
str(plot_data(p2))

p3 <- ggplot(mapping = aes(y = cyl)) +
  geom_point(aes(disp, colour = "mtcars"), data = mtcars) +
  geom_point(aes(displ * 61, colour = "mpg"), data = mpg)
str(plot_data(p3))

td <- temp_dir()
save_data(p3, td)
if (interactive()) show(td)

hadley/gg2v documentation built on May 17, 2019, 10:15 a.m.