Plotly r,按变量绘制线条样式 [英] Plotly r, line style by variable
本文介绍了Plotly r,按变量绘制线条样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试制作一个散点图,其中线型由因子变量指定,就像使用颜色一样,但我无法让它工作.
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)))
推荐答案
我自己找到了答案:
plot_ly(data=df,x=~x,y=~y,type="scatter",mode="lines",color=~as.factor(col),linetype=~as.factor(dash))
这篇关于Plotly r,按变量绘制线条样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文