Plotly r, line style by variable

若如初见. 提交于 2019-12-12 16:32:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!