I am developing an interactive scatterplot so that when the user rolls over a data point, a label is displayed. However, I would also like to add edges between certain data points.
I am successful at developing the interactive scatterplot using several libraries, including grid, gridSVG, lattice, and adegraphics. Below is a MWE: ########################################## library(grid) library(gridSVG) library(lattice) library(adegraphics) x = rnorm(10) y = rnorm(10) dat = data.frame(label = letters[1:10], x, y) customPanel2 <- function(x, y, ...) { for (j in 1:nrow(dat)) { grid.circle(x[j], y[j], r = unit(.5, "mm"), default.unit = "native", name = paste("point", j, sep = ".")) }} xyplot(y ~ x, panel = customPanel2, xlab = "x variable", ylab=NULL, scales=list(tck = c(1,0), y=list(at=NULL))) for (i in 1:nrow(dat)) { grid.text(as.character(dat$label)[i], x = 0.1, y = 0.01, just = c("left", "bottom"), name = paste("label", i, sep = "."), gp = gpar(fontface = "bold.italic"))} for (i in 1:nrow(dat)) { grid.garnish(paste("point", i, sep = "."), onmouseover = paste('highlight("', i, '.1.1")', sep = ""), onmouseout = paste('dim("', i, '.1.1")', sep = "")) grid.garnish(paste("label", i, sep = "."), visibility = "hidden")} grid.script(filename = "aqm.js", inline = TRUE) grid.export("interactiveScat.svg") ###################################### The resulting .svg file accomplishes everything I am aiming for - except that I also wish to add certain non-interactive edges. I tried to do this by incorporating the adeg.panel.edges method from the adegraphics library after defining the edges and the coordinates to be mapped. So, basically my MWE stays the exact same, except the xplot(...) function from before is replaced with: edges = matrix(c(1, 2, 3, 2, 4, 1, 3, 4), byrow = TRUE, ncol = 2) coords <- matrix(c(x[1], y[1], x[2], y[2], x[3], y[3], x[4], y[4]), byrow = TRUE, ncol = 2) xyplot(y ~ x, panel = function(customPanel2){adeg.panel.edges(edges, coords, lty = 1:4, cex = 5)}, xlab = "x variable", ylab=NULL, scales=list(tck = c(1,0), y=list(at=NULL))) It seems that this simply erases the interactive scatterplot made from the original xyplot, and simply outputs the static edge and coordinate image. I tried to follow the example as seen in ( http://finzi.psych.upenn.edu/library/adegraphics/html/adeg.panel.nb.html): edges <- matrix(c(1, 2, 3, 2, 4, 1, 3, 4), byrow = TRUE, ncol = 2) coords <- matrix(c(0, 1, 1, 0, 0, -1, -1, 0), byrow = TRUE, ncol = 2) xyplot(coords[,2] ~ coords[,1], panel = function(...){adeg.panel.edges(edges, coords, lty = 1:4, cex = 5)}) I am a bit at a loss as to how to troubleshoot this problem. I suspect it is a misuse of the ellipses function(...) in xyplot. I read the xyplot help manual, and note that they state: "It is useful to know in this context that all arguments passed to a high-level Lattice function (such as xyplot) that are not recognized by it are passed through to the panel function. It is thus generally good practice when defining panel functions to allow a ... argument." I feel I did define my panel function customPanel(...) using ellipses in my MWE: customPanel2 <- function(x, y, ...) Any suggestions are greatly appreciated! [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.