Skip to contents

This vignette compares ggplot2 output rendered directly with svglite against the same built plot converted through ggbuild_to_scene() and rendered by grrr::device_svg().

1) Empty ggplot (baseline)

p_empty <- ggplot() +
  theme_minimal(base_size = 8)

cmp_empty <- comparison_block("empty", p_empty)

ggplot2 + svglite

ggbuild_to_scene() + device_svg()

0.00.20.40.60.81.00.00.20.40.60.81.0
cat(sprintf("<p><strong>SVG signature differences:</strong> %s</p>\n", cmp_empty$diff_text))

SVG signature differences: line: 0 vs 12 | rect: 4 vs 1 | text: 0 vs 12 | chars: 1329 vs 2948

2) Faceted points example (README-style)

p_points <- ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
  geom_point() +
  facet_wrap(~am) +
  theme_minimal(base_size = 5) +
  theme(
    panel.spacing = grid::unit(4, "mm"),
    strip.text = element_text(size = 4),
    axis.title = element_text(size = 4.5),
    axis.text = element_text(size = 4),
    legend.title = element_text(size = 4.5),
    legend.text = element_text(size = 4)
  )

cmp_points <- comparison_block("points", p_points)

ggplot2 + svglite

0123452345101520253035wtmpgfactor(cyl)468

ggbuild_to_scene() + device_svg()

012345101520253035wtmpgfactor(cyl)468
cat(sprintf("<p><strong>SVG signature differences:</strong> %s</p>\n", cmp_points$diff_text))

SVG signature differences: polyline: 40 vs 0 | line: 0 vs 70 | rect: 7 vs 4 | text: 22 vs 18 | chars: 12964 vs 13322

What I looked for and found

# Compare key counts in a compact table for both examples.
summary_tbl <- function(label, cmp) {
  data.frame(
    example = label,
    metric = names(cmp$svglite_sig),
    svglite = as.numeric(cmp$svglite_sig),
    grrr = as.numeric(cmp$grrr_sig),
    delta = as.numeric(cmp$grrr_sig) - as.numeric(cmp$svglite_sig)
  )
}

tbl <- rbind(
  summary_tbl("empty", cmp_empty),
  summary_tbl("points", cmp_points)
)
knitr::kable(tbl, align = "lrrrr")
example metric svglite grrr delta
empty circle 0 0 0
empty polyline 0 0 0
empty polygon 0 0 0
empty line 0 12 12
empty rect 4 1 -3
empty text 0 12 12
empty chars 1329 2948 1619
points circle 35 35 0
points polyline 40 0 -40
points polygon 0 0 0
points line 0 70 70
points rect 7 4 -3
points text 22 18 -4
points chars 12964 13322 358

cat("\n")
cat("- In the empty baseline, layout primitives (rect/line/text) are present on both sides but not necessarily with the same counts due to different internal decomposition.\n")
  • In the empty baseline, layout primitives (rect/line/text) are present on both sides but not necessarily with the same counts due to different internal decomposition.
cat("- In the faceted points example, circle counts should now be non-zero in grrr and visually present; if not, it indicates a remaining point-shape/size translation issue.\n")
  • In the faceted points example, circle counts should now be non-zero in grrr and visually present; if not, it indicates a remaining point-shape/size translation issue.
cat("- Gridline density, label placement, and legend drawing can still differ because ggplot's gtable layout and guides are only approximated in the current bridge.\n")
  • Gridline density, label placement, and legend drawing can still differ because ggplot’s gtable layout and guides are only approximated in the current bridge.