gridSVG
Then and Now

Paul Murrell
The University of Auckland
December 2017

SVG

SVG is just another graphics format, like PDF or PNG, but it is the best format for graphics in a web page.

R Has Several SVG Devices

  • svg() from 'graphics'
  • devSVG() from 'RSvgDevice'
  • CairoSVG() from 'Cairo'
  • svgPlot() from 'SVGAnnotation'
  • svglite() from 'svglite'
  • grid.export() from 'gridSVG'

R Has Several SVG Devices

Two reasons to use gridSVG

#1. Fancy SVG features.


  grid.circle(x=.3, r=.4, name="circle")
  colors <- rev(sequential_hcl(5))
  radial <- radialGradient(colors)
  grid.gradientFill("circle", radial)
  grid.export()
          

Two reasons to use gridSVG

#1. Fancy SVG features.

Two reasons to use gridSVG

#2. Labelled and Structured SVG.


  grid.circle(x=.3, r=.4, name="circle")
  grid.export()
          

   <g id="circle.1">
       <circle id="circle.1.1" cx="129.6" cy="108" r="86.4"/>
   </g>
          

Two reasons to use gridSVG

#2. Labelled and Structured SVG.


  svg()
  grid.circle(x=.3, r=.4, name="circle")
  dev.off()
          

  <path d="M 352.800781 252 C 352.800781 363.339844 262.539062 
           453.601562 151.199219 453.601562 C 39.859375 
           453.601562 -50.398438 363.339844 -50.398438 252 
           C -50.398438 140.660156 39.859375 50.398438 
           151.199219 50.398438 C 262.539062 50.398438 
           352.800781 140.660156 352.800781 252 "/>
          

Two reasons NOT to

#1. 'grid' graphics only.

Two reasons NOT to

#1. 'grid' graphics only.


  perspPlot()
  grid.export()
          

Two reasons NOT to

#2. 'gridSVG' is SLOW.

Two more reasons NOT to

#3. No-one cares about fancy SVG features

Two more reasons NOT to

#4. No-one cares about labelling and structure

Problem Summary

'gridSVG' is a PAINFULLY SLOW and INCOMPLETE solution for problems that DO NOT EXIST.

Three Solutions

#1. The 'gridGraphics' package

Three Solutions

#1. The 'gridGraphics' package


  perspPlot()
  grid.echo()
  grid.export()
          

Three Solutions

#2. Speeding up 'gridSVG'

Three Solutions

#2. Speeding up 'gridSVG'


  library(profvis)
  p <- profvis({
      grid.export("old.svg")
  }, interval=.1)
            

Click the code to see the profiling output.

Three Solutions

#2. Speeding up 'gridSVG'


  library(profvis)
  p <- profvis({
      grid.export("new.svg")
  }, interval=.1)
            

Click the code to see the profiling output.

Three Solutions

#2. Speeding up 'gridSVG'

Three Solutions

#3. The 'BrailleR' package


  library(BrailleR)
  h <- hist(rnorm(10))
  MakeAccessibleSVG(h)
            

Click the code to see the accessible plot.

Summary

  • 'gridSVG' is NOT just 'grid' graphics.
  • 'gridSVG' is faster (than its former self)
  • Labelling and structure DO matter

Acknowledgements

  • The fancy SVG features in 'gridSVG' are largely thanks to the work of Simon Potter.
  • The ability to echo persp() plots as 'grid' plots in 'gridGraphics' is thanks to the work of Jason Wen.
  • 'BrailleR' is the brain child of Jonathon Godfrey; Volker Sorge contributed MakeAccessibleSVG().
  • Tauno Metsalu pointed out the bottleneck that was making 'gridSVG' so slow.
  • Winston Chang's 'profvis' package was used for profiling 'gridSVG' code.