How can I combine a line and scatter on same plotly chart?

前端 未结 3 500
说谎
说谎 2021-01-22 02:24

The two separate charts created from data.frame work correctly when created using the R plotly package.
However, I am not sure how to combine them into one (presumably with

3条回答
  •  面向向阳花
    2021-01-22 03:10

    The answer given by @LukeSingham does not work anymore with plotly 4.5.2. You have to start with an "empty" plot_ly() and then to add the traces:

    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")
    

提交回复
热议问题