knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(ggplot2) library(ggsvg)
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.