library(ggplot2)
library(devoutsvg)
#> Loading required package: devout
example_plot <- ggplot(mtcars) + 
  geom_density(aes(mpg, fill = as.factor(cyl))) + 
  labs(title = "Example plot") + 
  theme_bw() +    
  scale_fill_manual(values = c('4' = '#df536b', '6' = '#61d04f', '8' = '#2297e6'))

example_plot

my_css_decl <- "  
@keyframes pulse {
  from {transform: scale3d(1, 1, 1);}
  50%  {transform: scale3d(1.15, 1.15, 1.15);}
  to   {transform: scale3d(1, 1, 1);}
}

#polygon-0003 {
  animation-name: pulse;
  animation-duration: 4s;
  animation-fill-mode: both;
  animation-iteration-count: infinite;
}

rect:hover {
  fill: green !important;
}
"

svgfile <- tempfile(fileext = '.svg')
svgout(filename = svgfile, width = 8, height = 4,
       css_decl = my_css_decl)

  example_plot + 
    labs(title = "Example - CSS")
  
invisible(dev.off())
0.00 0.05 0.10 0.15 0.20 0.25 10 15 20 25 30 35 mpg density as.factor(cyl) 4 6 8 Example - CSS