Interactive point labels with gridSVG and ggplot2 v.0.9.0

前端 未结 4 793
我在风中等你
我在风中等你 2021-02-02 15:50

I\'d like to label points in a ggplot interactively, so that mousing over a point shows a label.

I\'m trying to adapt the answer given in this question so that it works

4条回答
  •  情书的邮戳
    2021-02-02 16:43

    Thanks to tracy for a good question and Julius for the very helpful answer.

    To make Julius's javascript work for me in Chrome and Safari, I had to replace this.id with this.correspondingUseElement.id. This makes sense because the single SVG element doesn't have an id for each geom_point, the id we want is attached to the elements.

    Even that didn't work for me in Firefox, so I changed it to attach the event listener to the elements themselves. Note that if the SVG is more complicated, it might have s other than the geom_points, so I added an if to only attach the event to the geom_point.XX elements. This works in Chrome, Safari, and Firefox for me:

    window.addEventListener("load",function(){
      var es = document.getElementsByTagName("use"); 
      for (i=0; i= 0) es[i].addEventListener("mouseover", f, false);
      }
      txt = (document.getElementById("text_place").getElementsByTagName("tspan"))[0];
    },false);
    

    (all other code same as Julius's)

提交回复
热议问题