使用R plotly包创建时,从data.frame创建的两个单独的图表正常工作.
但是,我不确定如何将它们组合成一个(大概是使用add_trace函数)
df <- data.frame(season=c("2000","2000","2001","2001"), game=c(1,2,1,2),value=c(1:4)) plot_ly(df, x = game, y = value, mode = "markers", color = season) plot_ly(subset(df,season=="2001"), x = game, y = value, mode = "line")
提前致谢
@LukeSingham给出的答案不再适用了plotly 4.5.2
.你必须以"空"开头,plot_ly()
然后添加痕迹:
df1 <- data.frame(season=c("2000","2000","2001","2001"), game=c(1,2,1,2), value=c(1:4)) df2 <- subset(df, season=="2001") plot_ly() %>% add_trace(data=df1, x = ~game, y = ~value, type="scatter", mode="markers") %>% add_trace(data=df2, x = ~game, y = ~value, type="scatter", mode = "lines")