[R] Lattice Package in R: Is it possible to develop an interactive “scatterplot/network”?

Bert Gunter bgunter.4567 at gmail.com
Thu Oct 29 15:11:50 CET 2015


You need to go back and read an R tutorial (e.g. the Intro to R one
that ships with R) about how functions pass ... arguments. Your
customPanel2 function does not use the ... argument passed to it, so
what you are trying to do by including it?

Beyond that, I do not have the patience to go through all the special
packages and functions you used. Maybe someone else will, and maybe
therein lies the problem. But the above suggests it might rather be a
failure of basic understanding.

Cheers,
Bert

Bert Gunter

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
   -- Clifford Stoll


On Wed, Oct 28, 2015 at 9:00 PM, Luck Buttered <luckbuttered at gmail.com> wrote:
> 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 at 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.



More information about the R-help mailing list