I'm trying a second Y axis to my line chart?
plot_ly(C,x =~Ymd,y=~Spots,mode="lines") # This works.
plot_ly(C,x =~Ymd,y=~ma90,mode="lines") # This works.
p<- plot_ly(C,x =~Ymd,y=~Spots,mode="lines")%>% # This doesn't work
add_trace(p,y=~ma90,mode="lines")
You need to specify yaxis = <new yaxis name>
in the trace.
library(plotly)
ay <- list(
tickfont = list(color = "red"),
overlaying = "y",
side = "right",
title = "second y axis"
)
p <- plot_ly() %>%
add_lines(x = ~1:3, y = ~10*(1:3), name = "slope of 10") %>%
add_lines(x = ~2:4, y = ~1:3, name = "slope of 1", yaxis = "y2") %>%
layout(
title = "Double Y Axis", yaxis2 = ay,
xaxis = list(title="x")
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.