Теперь я получил частичное решение для графика, однако мне все еще нужна ось y5, y6, потому что они находятся поверх другой оси y.Я думаю, что мне нужно изменить часть, position = "", но я не понял, какие цифры использовать.
Вот обновленный код ниже
library(plotly)
x <- 1:10
# Generate 4 different sets of outputs
y1 <- runif(10, 0, 1)
y2 <- runif(10, 100, 150)
y3 <- runif(10, 1000, 2000)
y4 <- runif(10, 40000, 50000)
y5 <- runif(10, 0, 1)
y6 <- runif(10, 100, 200)
y <- data.frame(y1, y2, y3, y4, y5, y6)
plot_ly(data = y, x = x, y = y$y1
,type = "scatter", mode = "lines", width = 1000, color = I("red")
,name = "name01") %>%
add_trace(x = x, y = y$y2, yaxis = "y2", color = I("blue"), name = "name02") %>%
add_trace(x = x, y = y$y3, yaxis = "y3", color = I("purple"), name = "name03") %>%
add_trace(x = x, y = y$y4, yaxis = "y4", color = I("green"), name = "name04") %>%
add_trace(x = x, y = y$y5, yaxis = "y5", color = I("orange"), name = "name05") %>%
add_trace(x = x, y = y$y6, yaxis = "y6", color = I("yellow"), name = "name06") %>%
layout(
yaxis = list(
showline = TRUE
,side = "left"
,anchor = "free"
,position = NA
,overlaying = NA
,color = "red"
,ticks = "outside"
,showgrid = FALSE
)
,yaxis2 = list(
showline = TRUE
,side = "right"
,anchor = "free"
,position = 1
,overlaying = "y"
,color = "blue"
,ticks = "outside"
,showgrid = FALSE
)
,yaxis3 = list(
showline = TRUE
,side = "left"
,anchor = NA
,position = NA
,overlaying = "y"
,color = "purple"
,ticks = "outside"
,showgrid = FALSE
)
,yaxis4 = list(
showline = TRUE
,side = "right"
,anchor = NA
,position = NA
,overlaying = "y"
,color = "green"
,ticks = "outside"
,showgrid = FALSE
)
,yaxis5 = list(
showline = TRUE
,side = "left"
,anchor = NA
,position = NA
,overlaying = "y"
,color = "orange"
,ticks = "outside"
,showgrid = FALSE
)
,yaxis6 = list(
showline = TRUE
,side = "right"
,anchor = NA
,position = NA
,overlaying = "y"
,color = "yellow"
,ticks = "outside"
,showgrid = FALSE
)
,showlegend = TRUE
,margin = list(
pad = 35, b = 60, l = 90, r = 200
)
,legend = list(x=0,y=0,orientation = "h")
)