Reusable Graphics

Overview

Reusing Raster Images

R -> PNG

png("xyplot.png")
xyplot(mpg ~ disp, mtcars)
dev.off()

Reusing Raster Images

Reusing Raster Images

PNG -> R

library(png)
map <- readPNG("map.png")
plot(data)
rasterImage(map)

Reusing Raster Images

 + 

Reusing Raster Images

Reusing Vector Images

R -> PDF

pdf("xyplot.pdf")
xyplot(mpg ~ disp, mtcars)
dev.off()

Reusing Vector Images

Reusing Vector Images

Reusing Vector Images

PostScript -> R

library(grImport)
PostScriptTrace("chess_game.eps", 
                "chess_game.xml")
chess <- readPicture("chess_game.xml")
pawn <- chess[119]
xyplot(..., 
       panel=function(...) {
                 grid.symbols(pawn, ...)
             })

Reusing Vector Images

Reusing Vector Images

Reusing Marked Up Images

R -> R

library(grid)
library(lattice)
xyplot(mpg ~ disp, mtcars)

Reusing Marked Up Images

Reusing Marked Up Images

xyplot(mpg ~ disp, mtcars)
grid.ls()

viewport[ROOT]
  rect[plot_01.background]
  viewport[plot_01.toplevel.vp]
    viewport[plot_01.xlab.vp]
      text[plot_01.xlab]
    viewport[plot_01.ylab.vp]
      text[plot_01.ylab]

Reusing Marked Up Images

xyplot(mpg ~ disp, mtcars)
grid.edit("plot_01.ylab", rot=0)

Reusing Marked Up Images

Reusing Marked Up Images

R -> SVG

library(gridSVG)
xyplot(mpg ~ disp, mtcars)
grid.export("svg-plot.svg")

Reusing Marked Up Images

Reusing Marked Up Images

<svg>
  <rect id="plot_01.background.1.1"/>
  <g id="plot_01.toplevel.vp.1">
    <g id="plot_01.xlab.vp.1">
      <text id="plot_01.xlab.1">
        disp
      </text>
...

Reusing Marked Up Images

xyplot(mpg ~ disp, mtcars)
grid.garnish("plot_01.xyplot.points.panel.1.1", 
             title=rownames(mtcars))
grid.export("svg-plot.svg")

Reusing Marked Up Images

Reusing Marked Up Images

SVG -> R

library(XML)
svg <- xmlParse("Multilingualism.svg")
polys <- getNodeSet(svg, "//svg:polygon")
invisible(lapply(polys[!retain], remove))
saveXML(svg, "Multilingualism-Auckland.svg")

Reusing Marked Up Images

Reusing Marked Up Images

Licencing

It is important to remember to provide permission for others to use your graphic

 versus  ©

Summary

Acknowledgements