title: Interactive scatter plots in R, overlay/hover summary/tooltip as user supplied plot function
body: <p>I have been looking into interactive plots in R. I know that there are several packages to create interactive plots, especially scatterplots, but I am looking for a certain functionality.</p>
  
  <p>For example <a href="https://data.nozav.org/app/scatterD3/" rel="noreferrer">this plot</a>. One can hover with the mouse over the buttons to get a small numerical summary of the data behind the point, i.e. a tooltip.</p>
  
  <p>When you have a data set with more variables, it is often nice to explore/visualize scores from PCA, or do multi-dimensional-scaling(MDS). But if one would plot the data in an interactive manner, like the example above, the summary when one hovers over the point is not giving so much information, i.e. just a long list of numbers. It would be more nice to be able to generate a custom plot to display, instead of just displaying the numerical values.</p>
  
  <p><strong>So my question is:</strong></p>
  
  <p>Is it possible, (within some of the packages available in R), to generate a visual summary when one hovers over a point in a scatter plot. This could be a barplot, or just some user-specified plot function, that takes one row from the data.frame as an argument.</p>
  
  <p>If this is possible, then it would greatly help in understanding the results from MDS in a quick manner.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Here is some code to do MDS on the iris data set:</p>
  
  <pre><code>library(ggplot2)
  library(plotly)
  d &lt;- dist(iris[,-5]) # euclidean distances between the rows
  fit &lt;- cmdscale(d,eig=TRUE, k=2) # k is the number of dim
  
  # Put coordinates and original data in one data.frame
  x &lt;- fit$points[,1]
  y &lt;- fit$points[,2]
  pDat &lt;- data.frame(x=x,y=y)
  pDat &lt;- cbind(pDat,iris)
  p &lt;- ggplot(pDat) + geom_point(aes(x,y))
  ggplotly(p)
  </code></pre>
  
  <p>First, now the tooltip only includes the x,y coordinates. I would like the tooltip to contain the values for the original 4 variables. Then instead of the original 4 variables behind the datapoint, I would like to display the tooltip as a barplot. The MDS preserves the distance between the data points, so one would be able to hover gradually with the mouse, and see the barplot, almost change continuously, because the distances are preserved. In my usage case I have 30 variables behind each point, so a barplot summary gives more visual information than 30 numerical values.</p>