Learn R Programming

svgedit (version 1.0.0)

draw: Replace an svg object by a ggplot2 graph

Description

Replace an svg object by a ggplot2 graph

Usage

draw(
  input_svg,
  output_svg,
  plots = NULL,
  plot_scale = NULL,
  text = NULL,
  images = NULL,
  dpi = 150
)

Value

Invisibly returns NULL. The output svg file is written to output_svg.

Arguments

input_svg

Path to the input svg file

output_svg

Path to the output svg file

plots

A named list of ggplot2 objects. The list names should correspond to the labels of the svg elements to be replaced.

plot_scale

A named list of numeric values to scale the inserted plots. The names should correspond to the labels of the svg elements to be replaced.

text

A named list of character vectors. The list names should correspond to the labels of the svg text elements to be modified. Each character vector will be used to replace "" placeholders in the text element in order.

images

A named list of paths to image files. The list names should correspond to the labels of the svg image elements to be replaced.

dpi

The resolution to use when rendering the ggplot2 objects.

Examples

Run this code
library(ggplot2)
# Create a simple plot
p <- ggplot(mtcars, aes(x = mpg, y = wt)) + geom_point()
# Use draw() to insert the plot into an SVG template
input_svg <- system.file("examples", "Template.svg", package = "svgedit")
draw(
  input_svg = input_svg,
  output_svg = tempfile(fileext = ".svg"),
  plots = list(panel_A = p)
)

Run the code above in your browser using DataLab