0

我正在尝试在 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")
    )

如果有人可以提供一些建议,我将不胜感激。

4

1 回答 1

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")
    )
于 2018-02-05T17:33:34.710 回答