我正在尝试使用R中的plotly
制作双轴图。但是,我无法使用以下代码命名第一个y轴:https://plot.ly/r/multiple-axes/
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")
)
如果有人可以提供一些建议,我将非常感激。
答案 0 :(得分:1)
你在找这个:
library(plotly)
library(dplyr)
ay2 <- list(
tickfont = list(color = "red"),
side = "left",
title = "first y axis"
)
ay <- list(
tickfont = list(color = "red"),
overlaying = "y",
side = "right",
title = "second y axis"
)
plot_ly() %>%
add_lines(x = ~1:3, y = ~10*(1:3), name = "slope of 10", yaxis = "y1") %>%
add_lines(x = ~2:4, y = ~1:3, name = "slope of 1", yaxis = "y2") %>%
layout(
title = "Double Y Axis", yaxis2 = ay, yaxis = ay2,
xaxis = list(title="x")
)