最简单的方法是从默认情况下关闭所有迹线开始,然后单击图例分别进行切换
plot_ly(data=df, x=year,y=values,color=team,mode="markers", visible="legendonly")
如果要从已经可见的一些点开始,而另一些则不存在,则需要使用两条迹线,第二条迹线带有visible="legendonly"
。如果您采用这种方式,则还需要手动选择颜色。
plot_ly(data=df[which(df$team=="a"),], x=year,y=values,
color=team, colors = "blue", mode="markers") %>%
add_trace(data=df[which(df$team=="b"),], x=year,y=values, color=team,
colors="green", mode="markers", visible="legendonly")
您可以使用该layout
功能控制轴和刻度。要仅在单位间隔内放置刻度线,可以使用此选项
plot_ly(data=df[df$team=="a",], x=year,y=values,color=team, colors = "blue", mode="markers") %>%
add_trace(data=df[df$team=="b",], x=year,y=values, color=team, colors = "green", mode="markers", visible="legendonly") %>%
layout(xaxis = list(autotick = FALSE, tickmode="linear", tick0 =2000, dtick=1, range=c(1999.5,2003.5)),
yaxis = list(autotick = FALSE, tickmode="linear", tick0 =0, dtick=1, range=c(0,5)) )
可在https://plot.ly/r/reference/中找到对plotly API中所有选项的完整描述。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句