Skip to contents

Sizes the output with dag_size(), so that one data unit equals one SVG pixel (times ggplot_dag(zoom =)) at scale 1, at 96 dpi.

Usage

ggsave_dag(filename, plot = ggplot2::last_plot(), scale = 1, ...)

Arguments

filename

File to write to, passed to ggplot2::ggsave().

plot

A plot from ggplot_dag() (or any ggplot with coord_fixed() limits set the same way, e.g. via manual assembly with dag_layers()).

scale

Resolution multiplier (applied to dpi, not physical size).

...

Passed on to ggplot2::ggsave().

Value

The result of ggplot2::ggsave(), invisibly.

Details

scale raises resolution (dpi = 96 * scale) rather than the physical width/height: line widths and text are set in absolute units (points), so scaling the canvas size at a fixed dpi would make them relatively thinner/smaller against the (now larger) node spacing. Scaling dpi instead keeps every element's proportions exactly as dagviz draws them, just at higher resolution.

For a fixed-size plot (the ggplot_dag() default) the output also makes room for any legend or title. For a plot with fixed_size = FALSE (or manual assembly), the size is the view box's alone, so a legend or title shrinks the panel to fit.

Examples

dag <- as_dag(data.frame(from = c("a", "a", "b"), to = c("b", "c", "c")))
p <- ggplot_dag(dag)
ggsave_dag(tempfile(fileext = ".png"), p)