Brad
Brad

Reputation: 33

How to create a scatter plot that will link points that are from a same category on mouse hover?

I want to create a scatter plot that will link points that share a particular attribute when hovered over and also display a tooltip, similar to the example here https://i.sstatic.net/fAWem.gif

I am currently using ggvis to make the plot, although I'm not sure it supports this functionality. The visualization will be displayed in shiny.This is what my code to make the visualization looks like at the moment. The categorical variable that I want the points to be joined by is Choice_2.

plot_data %>%
ggvis(x= ~X,y= ~Y,  size= ~Size_val,stroke := "white") %>%
layer_points(fill= ~Choice_1, opacity := I(2/5)) %>%
scale_numeric(property = 'size', domain = c(0.01,0.52),range = c(100,5200))%>%
hide_legend(scales = 'size') %>%
bind_shiny("ggvis", "ggvis_ui")

Any help or references would be much appreciated.

Upvotes: 0

Views: 261

Answers (2)

Pork Chop
Pork Chop

Reputation: 29387

As mentioned by @vck look into Rcharts. Note that the example is taken from here

library(rCharts)
r1<- nPlot(mpg ~ wt, group = 'cyl', data = mtcars, type="scatterChart")
r1$chart(tooltipContent = "#! function(key, x, y, e,graph){
return '<b>carb</b>: ' + e.point.carb
} !#")
r1$chart(size = '#! function(d){return d.disp} !#')
r1

Sample

Upvotes: 1

vck
vck

Reputation: 837

Try this;

require(devtools)
install_github('rCharts', 'ramnathv')
library(rCharts)

x=rnorm(100)
y=rnorm(100)
data<-data.frame(y,x)
rPlot(y~x, data = data, type = "point")

rCharts is a useful package that you can use polycharts and highcharts with R.

Upvotes: 0

Related Questions