2

I have a ggplot with points on it. I want to group these points into group based on their location, but I want to do it interactively with the "lasso" tool in plotly.

I can't figure out how to save the info from the group I've lassoed. I basically want to add a column in my df for "group" then pick group 1 with a lasso, group 2 with a lasso, etc.

I have figured out how to plot it and lasso points, but I want to say

df$group[df____lasso choose___] <- 1

I figure there must be a way.

 set.seed(1)
 df <- data.frame(matrix(nrow=300,ncol=3))
 colnames(df) <- c("X","Y","Group")
 df[,1:2] <- runif(600,0,200)

 library(ggplot2)
 library(plotly)

 p <- ggplot(df,aes(x=X,y=Y))+
   geom_point()
 ggplotly(p)
Jake L
  • 987
  • 9
  • 21
  • Are you planning to use shiny? If so `event_data(event = "plotly_selected")` would be an option. You might want to have a look at [this](https://plotly-r.com/client-side-linking.html) (Chapter 16 & 17). – ismirsehregal Jul 17 '19 at 09:55

0 Answers0