R 在仅有1条轨迹的绘图图表中显示右y轴
在R plotly中,我想显示一个在左右两侧都有y轴标签的单线图。我明白,但我找不到任何地方显示如何在图表上只使用1个轨迹。下面是一个基本示例-它只显示左侧的y轴,但我希望它显示在两侧:R 在仅有1条轨迹的绘图图表中显示右y轴,r,plotly,r-plotly,R,Plotly,R Plotly,在R plotly中,我想显示一个在左右两侧都有y轴标签的单线图。我明白,但我找不到任何地方显示如何在图表上只使用1个轨迹。下面是一个基本示例-它只显示左侧的y轴,但我希望它显示在两侧: library(plotly) ay <- list( tickfont = list(color = "red"), overlaying = "y", side = "right", title = "second
library(plotly)
ay <- list(
tickfont = list(color = "red"),
overlaying = "y",
side = "right",
title = "second y axis"
)
fig <- plot_ly()
fig <- fig %>% add_lines(x = ~1:3, y = ~10*(1:3), name = "slope of 10")
fig <- fig %>% layout(
title = "Double Y Axis", yaxis2 = ay,
xaxis = list(title="x")
)
fig
library(plotly)
ay您可以在新轴中添加相同的值,如下所示:
library(plotly)
#Setup
ay <- list(
tickfont = list(color = "red"),
overlaying = "y",
side = "right",
title = "second y axis"
)
#Plot
fig <- plot_ly()
fig <- fig %>% add_lines(x = ~1:3, y = ~10*(1:3), name = "slope of 10", yaxis = "y2")
fig <- fig %>%
add_lines(x = ~1:3, y = ~10*(1:3), name = "slope of 10") %>%
layout(
title = "Double Y Axis", yaxis2 = ay,
xaxis = list(title="x")
)
library(plotly)
#设置
唉,这对你有帮助吗:就是这样!增加透明度并关闭hoverinfo可以做到这一点
#Plot 2
fig <- plot_ly()
fig <- fig %>% add_lines(x = ~1:3, y = ~10*(1:3), name = "slope of 10", yaxis = "y2")
fig <- fig %>%
add_lines(x = ~1:3, y = ~10*(1:3), name = "slope of 10") %>%
layout(
title = "Double Y Axis", yaxis2 = ay,
xaxis = list(title="x"),showlegend = FALSE
)