if (interactive()) {
## time series plot
treering2 <- window(treering, start=1)
playwith(plot(treering2, xlim=c(0,300)),
time.mode = TRUE,
labels = paste(time(treering2), "CE"))
library(lattice)
## multi-panel lattice plots
playwith(xyplot(Income ~ log(Population / Area) | state.region,
data = data.frame(state.x77)),
label.style = gpar(col="red", fontfamily="HersheySans",
cex=0.7))
## scrollbar controlling a smoothing parameter
xx <- rnorm(50)
playwith(plot(density(xx, bw = cur.time), panel.last = rug(xx)),
time.vector = seq(0.1, 1, by=0.05))
## brushing multivariate scatterplots
playwith(splom(environmental))
## simple spin and zoom for 3D plots
playwith(wireframe(volcano, drape=TRUE))
## a minimalist grid plot
gridPlot <- function(x, y, xlim = NULL, ylim = NULL) {
if (is.null(xlim)) xlim <- extendrange(x)
if (is.null(ylim)) ylim <- extendrange(y)
grid.newpage()
pushViewport(plotViewport())
grid.rect()
pushViewport(viewport(xscale=xlim, yscale=ylim,
name="theData"))
grid.points(x, y)
grid.xaxis()
grid.yaxis()
}
playwith(gridPlot(1:10, 11:20), viewport="theData")
## acting like a dialog box (confirm close)
subTools <- list("identify", "clear", "zoom", "zoomout", "zoomfit")
confirmClose <- function(playState) {
if (gWidgets::gconfirm("Close window and report IDs?")) {
cat("Indices of identified data points:
")
print(rbind(playState$ids)$which)
all.ids <- do.call(rbind, playState$ids)$which
print(all.ids)
return(FALSE)
} else TRUE # don't close
}
xy <- list(x=rnorm(20), y=rnorm(20))
playwith(plot(xy), on.close=confirmClose, modal=TRUE,
win.size=c(360, 360), show.call=FALSE,
top=NULL, left=subTools)
## local variables appearing in the plot call are stored
globalOne <- rnorm(100)
localStuff <- function() {
localOne <- rnorm(100)
playwith(plot(localOne, globalOne))
}
localStuff()
## list objects that have been copied and stored
sapply(playDevCur()$env, object.size)
## see help(playwith.API) for examples of new tools.
}
Run the code above in your browser using DataLab