Reputation: 375
I am trying to make a scatter plot where the line style is specified by a factor variable, just as one does with colors, but I can't get it to work.
library(plotly)
df <- data.frame(x=rnorm(20),y=rnorm(20),col=c(rep(1,10),rep(2,10)),dash=c(1,2))
df <- df[order(df[,1]),]
plot_ly(data=df,x=~x,y=~y,type="scatter",mode="lines",color=~as.factor(col),line=list(dash=~as.factor(dash)))
Upvotes: 2
Views: 1126
Reputation: 375
I found the answer myselfes:
plot_ly(data=df,x=~x,y=~y,type="scatter",mode="lines",color=~as.factor(col),linetype=~as.factor(dash))
Upvotes: 1