I'm trying to produce a plotly graphic with a slider which would color the points according to several classification schemes. Here is an example
library(plotly)
library(reshape2)
# create data
size = 100
groups = 8
x = as.data.frame(matrix(runif(2*size),size,2))
colnames(x)[1:2]=c('x','y')
for(i in 1:groups)
x[[paste0('set',i)]] = factor(sample(i,size,replace=T))
mx = melt(x,measure.vars=paste0("set",1:groups))
colnames(mx)[3:4] = c("set","group")
I'd like to have the following plots in a slider
p1 = ggplot(data=subset(mx,set=="set1"),aes(x=x,y=y,color=factor(group))) + geom_point() + theme_minimal() + labs(x="",y="")
ggplotly(p1)
p2 = ggplot(data=subset(mx,set=="set2"),aes(x=x,y=y,color=factor(group))) + geom_point() + theme_minimal() + labs(x="",y="")
ggplotly(p2)
p3 = ggplot(data=subset(mx,set=="set3"),aes(x=x,y=y,color=factor(group))) + geom_point() + theme_minimal() + labs(x="",y="")
ggplotly(p3)
# etc
I've tried the following but the result gives me only the members of the first color group.
# plot
p = ggplot(data=mx,aes(x=x,y=y,color=factor(group),group=set,frame=set)) + geom_point() + theme_minimal() + labs(x="",y="")
ggplotly(p) %>% animation_opts(frame=1000,transition=600,redraw=F)
Thanks.