ropensci / unconf17

Website for 2017 rOpenSci Unconf
http://unconf17.ropensci.org
64 stars 12 forks source link

svg...medium? #68

Closed ldecicco-USGS closed 7 years ago

ldecicco-USGS commented 7 years ago

svglite is a handy package, but inserting an "id" on a polygon (for instance) becomes a bit tricky. Giving lines/points/paths/etc custom id's would greatly increase the potential for neat data visualizations using custom CSS and/or javascript. With my limited experience, I've created an svg from either svglite or ggsave, then use the xml2 package to get the id's in there. That might sound easy enough...but in actuality it was kind of a pain (to me at least...).

I'm not sure the best way, but workflows such as this would be awesome:

  svglite(tmp1)
  plot(x, y, id="cats")
  lines(x, z, id="cows")
  dev.off()

or....

fancy_ggplot <- ggplot(data = df) +
   geom_point(aes(x, y), id="cats") +
   geom_line(aes(x, z), id="cows")

ggsave(fancy_ggplot, "fancy.svg")

The svg output would now allow me to set linewidths and colors and whatnot on "cows" and "cats" in the CSS. I could also make some javascript functions that depend on the Id.

Maybe to get real fancy....we could also set javascript functions or CSS style directly in the R code too.

This is something our group has struggled with and we're excited to hear the best way to go. Maybe there already is a perfectly acceptable way to do this, in which case I'd be super-happy to hear it!

noamross commented 7 years ago

I think a similar strategy is used by ggiraph, relying on the rvg graphics device. I believe one can add IDs to ggplot elements by adding a data_id aesthetic to the ggplot.