Convenience wrapper around plot_data() and utils::write.csv() for publishing the numbers behind a figure next to the figure itself.

write_plot_data(plot, file, layer = NULL)

Arguments

plot

A GgnextPlot.

file

Output path. With multiple layers and no layer given, the layer index is inserted before the extension (fig.csv -> fig-1.csv, fig-2.csv).

layer

Optional layer index (see plot_data()).

Value

The file path(s) written, invisibly.

Examples

p <- ggnext(cars, aes(speed, dist)) + geom_point()
out <- file.path(tempdir(), "cars.csv")
write_plot_data(p, out)