2

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)))
Tobias D
  • 345
  • 2
  • 12

1 Answers1

1

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))
Tobias D
  • 345
  • 2
  • 12