knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(ggplot2)
library(ggsvg)

Using an SVG icon from the web

This example grabs an SVG from the internet and then uses it as a plotting glyph without further modification.

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Read SVG from the web
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
car_url <- 'https://www.svgrepo.com/download/114837/car.svg'
car_svg <- paste(readLines(car_url), collapse = "\n")
# Local cache
car_svg <- paste(readLines("svg/car-svgrepo-com.svg"), collapse = "\n")
grid::grid.draw( svg_to_rasterGrob(car_svg) )
ggplot(mtcars) + 
  geom_point_svg(
    aes(mpg, wt),
    svg = car_svg,
    size = 8
  ) + 
  theme_bw()


coolbutuseless/ggsvg documentation built on Sept. 14, 2024, 5:48 p.m.