library(lattice) xyplot(mpg ~ disp, mtcars, pch=16) abline(h=20)
Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...): plot.new has not been called yet
library(gridSVG) plot(mpg ~ disp, mtcars, pch=16) grid.export("plot.svg")
Error in grobToDev.default(gTree, dev): We shouldn't be here!
plot(mpg ~ disp, mtcars, pch=16) library(gridGraphics) grid.echo()
pf <- function() plot(mpg ~ disp, mtcars, pch=16) pushViewport(viewport(x=0, y=0, width=2/3, height=2/3, just=c("left", "bottom"))) grid.echo(pf, newpage=FALSE)
plot(mpg ~ disp, mtcars) |
grid.echo() |
grid.ls()
graphics-plot-1-points-1 graphics-plot-1-bottom-axis-line-1 graphics-plot-1-bottom-axis-ticks-1 graphics-plot-1-bottom-axis-labels-1 graphics-plot-1-left-axis-line-1 graphics-plot-1-left-axis-ticks-1 graphics-plot-1-left-axis-labels-1 graphics-plot-1-box-1 graphics-plot-1-xlab-1 graphics-plot-1-ylab-1
grid.edit("graphics-plot-1-bottom-axis-labels-1", rot=45)
par(mfrow=c(3,6), oma=rep(1, 4), mar=c(1,1,1,1)) for(j in rownames(clusterprops)) { mosaicplot(CC ~ exposure, mosaicdata, ...) }
grid.echo() grid.edit("text-1", grep=TRUE, global=TRUE, y=unit(1, "npc"), hjust=.2, vjust=0, rot=20)
Draw a map with maps, which uses graphics
states <- map("state", fill=TRUE, plot=FALSE) statePolygons <- map2SpatialPolygons(states, IDs, proj4string=CRS("+proj=longlat +datum=WGS84")) plot(statePolygons)
Convert the map to grid with gridGraphics
grid.echo()
Add audio tips and export to SVG with gridSVG
for (i in seq_along(stateGrobs)) { grid.garnish(stateGrobs[[i]], onclick=paste0("speak(", stateNames[i], ")")) } grid.export("map-gridSVG-audio.svg")
Add tooltips and export to SVG with gridSVG
for (i in seq_along(stateGrobs)) { grid.garnish(stateGrobs[[i]], title=stateNames[i]) } grid.export("map-gridSVG-tooltips.svg")
The following R packages were used in the construction of these slides:
Thanks to Lize van der Merwe and Jonathon Godfrey for providing problems to my solution.
plot(mpg ~ disp, mtcars, pch=16) grid.echo() grid.export("plot.svg")
xyplot(mpg ~ disp, mtcars, pch=16, panel=function(...) { panel.xyplot(...); panel.abline(h=20) })
print(xyplot(mpg ~ disp, mtcars, pch=16), prefix="mix-plot") downViewport("mix-plot.panel.1.1.vp") cvp <- current.viewport() addLine <- function() { par(mar=rep(0, 4), xaxs="i", yaxs="i") plot.new() plot.window(xlim=cvp$xscale, ylim=cvp$yscale) abline(h=20) } grid.echo(addLine, newpage=FALSE)