Information about converting ggplot to SVG #5
Replies: 2 comments 3 replies
-
Initial findings. I spent some time playing around with a bunch of different ggplots code, simple and complex. Here is what I learned from that exploration. Here's the basic code I used to play around with ggplots to SVG. I kept changing the ggplot code, rerunning, and then "inspecting" the SVG in my browser. library(tidyverse)
p_fn <- 'p.svg'
example_dat <- tibble(day = c(1:3,2:4),
value = c(5,7,2, 1,4.5,5.3),
group = c(rep('site1', 3), rep('site2', 3)))
p <- ggplot(example_dat, aes(x = day, y = value, color = group)) +
geom_line()
ggsave(p_fn, p, width=10, height=5, units='in')
file.show(p_fn) |
Beta Was this translation helpful? Give feedback.
-
From #11 we learn some things. What I see as most promising is that we can export different layers - plot, background, margins - as separate svgs and work with them that way. We can use It's still tbd on whether the colors could be used as a proxy to add class or id selectors to individual components. There are small differences in sizing, but it is very slight. That means if frames/svgs are regenerated, they all need to be done to keep them scaled the same. I'd expect that anyways. |
Beta Was this translation helpful? Give feedback.
-
Purpose: We want to be able to get faster at inserting visuals into our websites. Ideally, we will have SVG charts but not everyone knows how to code up SVG and we can't always build them manually using Illustrator. @ceenell had the idea to just save ggplots as SVG (
ggsave('file.svg')
) and then using the output to stylize and possibly animate. They successfully accomplished this sort of post-SVG manipulation here in flow-tiles, but we want to better understand the ggplot --> SVG relationship to see if there are patterns that we can use in the future. It would be great for people to make ggplots and then us easily insert them as SVG on our sites without a ton of work.Beta Was this translation helpful? Give feedback.
All reactions