问题
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)))
回答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))
来源:https://stackoverflow.com/questions/48901064/plotly-r-line-style-by-variable