Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this:</p> <pre><code>library(ggplot2) library(gridSVG) library(proto) library(rjson) mtcars2 &lt;- data.frame(mtcars, names = rownames(mtcars)) geom_point2 &lt;- function (...) { GeomPoint2$new(...) } GeomPoint2 &lt;- proto(ggplot2:::Geom, { objname &lt;- "point" draw_groups &lt;- function(., ...) .$draw(...) draw &lt;- function(., data, scales, coordinates, na.rm = FALSE, ...) { data &lt;- remove_missing(data, na.rm, c("x", "y", "size", "shape"), name = "geom_point") if (empty(data)) return(zeroGrob()) name &lt;- paste(.$my_name(), data$PANEL[1], sep = ".") with(coord_transform(coordinates, data, scales), ggname(name, pointsGrob(x, y, size=unit(size, "mm"), pch=shape, gp=gpar( col=alpha(colour, alpha), fill = alpha(fill, alpha), label = label, fontsize = size * .pt))) ) } draw_legend &lt;- function(., data, ...) { data &lt;- aesdefaults(data, .$default_aes(), list(...)) with(data, pointsGrob(0.5, 0.5, size=unit(size, "mm"), pch=shape, gp=gpar( col = alpha(colour, alpha), fill = alpha(fill, alpha), label = label, fontsize = size * .pt) ) ) } default_stat &lt;- function(.) StatIdentity required_aes &lt;- c("x", "y") default_aes &lt;- function(.) aes(shape=16, colour="black", size=2, fill = NA, alpha = NA, label = NA) }) p &lt;- ggplot(mtcars2, aes(mpg, wt, label = names)) + geom_point2() +facet_wrap(~ gear) print(p) grob_names &lt;- grid.ls(print = FALSE)$name point_grob_names &lt;- sort(grob_names[grepl("point", grob_names)]) point_grobs_labels &lt;- lapply(point_grob_names, function(x) grid.get(x)$gp$label) jlabel &lt;- toJSON(point_grobs_labels) grid.text("value", 0.05, 0.05, just = c(0, 0), name = "text_place", gp = gpar(col = "red")) script &lt;- ' var txt = null; function f() { var id = this.id.match(/geom_point.([0-9]+)\\.points.*\\.([0-9]+)$/); txt.textContent = label[id[1]-1][id[2]-1]; } window.addEventListener("load",function(){ var es = document.getElementsByTagName("circle"); for (i=0; i&lt;es.length; ++i) es[i].addEventListener("mouseover", f, false); txt = (document.getElementById("text_place").getElementsByTagName("tspan"))[0]; },false); ' grid.script(script = paste("var label = ", jlabel)) grid.script(script = script) gridToSVG() </code></pre> <p>there were no big changes, but I had to add</p> <pre><code>mtcars2 &lt;- data.frame(mtcars, names = rownames(mtcars)) </code></pre> <p>and then</p> <pre><code>p &lt;- ggplot(mtcars, aes(mpg, wt, label = rownames(mtcars))) + geom_point2() + facet_wrap(~ gear) </code></pre> <p>also changes to</p> <pre><code>p &lt;- ggplot(mtcars2, aes(mpg, wt, label = names)) + geom_point2() +facet_wrap(~ gear) </code></pre> <p>because we have <code>rownames(mtcars)</code></p> <pre><code>rownames(mtcars) [1] "Mazda RX4" "Mazda RX4 Wag" "Datsun 710" "Hornet 4 Drive" [5] "Hornet Sportabout" "Valiant" "Duster 360" "Merc 240D" [9] "Merc 230" "Merc 280" "Merc 280C" "Merc 450SE" ..... </code></pre> <p>and then labels (which we manage to get with other modifications) remain the same, i.e. not rearranged by <code>gears</code>, only split by it:</p> <pre><code>point_grobs_labels [[1]] [1] "Mazda RX4" "Mazda RX4 Wag" "Datsun 710" "Hornet 4 Drive" [5] "Hornet Sportabout" "Valiant" "Duster 360" "Merc 240D" [9] "Merc 230" "Merc 280" "Merc 280C" "Merc 450SE" [13] "Merc 450SL" "Merc 450SLC" "Cadillac Fleetwood" [[2]] .... </code></pre> <p>but having these label names as a column fixes the problem. </p> <pre><code>point_grobs_labels [[1]] [1] "Hornet 4 Drive" "Hornet Sportabout" "Valiant" "Duster 360" [5] "Merc 450SE" "Merc 450SL" "Merc 450SLC" "Cadillac Fleetwood" [9] "Lincoln Continental" "Chrysler Imperial" "Toyota Corona" "Dodge Challenger" [13] "AMC Javelin" "Camaro Z28" "Pontiac Firebird" [[2]] .... </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload