我想隐藏这一系列情节的传说。有没有办法在 R Plotly 中的每个子图的 x 轴上方添加 x 轴标签,或者在 y 轴左侧添加 y 轴标签?
我尝试在将它们与子图函数组合之前将它们添加到每个图中,但只显示一个标题/标签。我已经尝试过 ggplot 中的方面,然后是 ggplotly 中的方面,但最终的图表不如用plotly制作的图表那么有吸引力。这是示例代码:
library(plotly)
fig1 <- plot_ly(x = c(3, 4, 5), y = c(1000, 1100, 1200), type = 'scatter', mode = 'lines+markers')
fig2 <- plot_ly(x = c(2, 3, 4), y = c(100, 110, 120), type = 'scatter', mode = 'lines+markers')
fig3 <- plot_ly(x = c(0, 1, 2), y = c(10, 11, 12), type = 'scatter', mode = 'lines+markers')
fig <- subplot(fig1, fig2, fig3, nrows = 3, shareX = TRUE) %>%
hide_legend() %>%
layout(title = list(text = "Stacked Subplots"),
plot_bgcolor='#e5ecf6',
xaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff'),
yaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff'))
fig
fig1 <- plot_ly(x = c(3, 4, 5), y = c(1000, 1100, 1200), type = 'scatter', mode = 'lines+markers') %>%
layout(annotations =
list(x = 1, y = -0.1, text = "Fig1",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='bottom', xshift=0, yshift=0,
font=list(size=15, color="red")))
fig2 <- plot_ly(x = c(2, 3, 4), y = c(100, 110, 120), type = 'scatter', mode = 'lines+markers') %>%
layout(annotations =
list(x = 1, y = -0.1, text = "Fig2",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='bottom', xshift=0, yshift=0,
font=list(size=15, color="red")))
fig3 <- plot_ly(x = c(0, 1, 2), y = c(10, 11, 12), type = 'scatter', mode = 'lines+markers') %>%
layout(annotations =
list(x = 1, y = -0.1, text = "Fig3",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='bottom', xshift=0, yshift=0,
font=list(size=15, color="red")))
fig <- subplot(fig1, fig2, fig3, nrows = 3, shareX = TRUE) %>%
hide_legend() %>%
layout(title = list(text = "Stacked Subplots"),
plot_bgcolor='#e5ecf6',
xaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff'),
yaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff'))
fig
这会将标签放在图的左侧:
fig1 <- plot_ly(x = c(3, 4, 5), y = c(1000, 1100, 1200), type = 'scatter', mode = 'lines+markers') %>%
layout(annotations =
list(x = -0.1, y = 0.5, text = "Fig1",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='bottom', xshift=0, yshift=0,
textangle=-90,
font=list(size=15, color="red")))
fig2 <- plot_ly(x = c(2, 3, 4), y = c(100, 110, 120), type = 'scatter', mode = 'lines+markers') %>%
layout(annotations =
list(x = -0.1, y = 0.5, text = "Fig2",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='bottom', xshift=0, yshift=0,
textangle=-90,
font=list(size=15, color="red")))
fig3 <- plot_ly(x = c(0, 1, 2), y = c(10, 11, 12), type = 'scatter', mode = 'lines+markers') %>%
layout(annotations =
list(x = -0.1, y = 0.5, text = "Fig3",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='bottom', xshift=0, yshift=0,
textangle=-90,
font=list(size=15, color="red")))
fig <- subplot(fig1, fig2, fig3, nrows = 3, shareX = TRUE) %>%
hide_legend() %>%
layout(title = list(text = "Stacked Subplots"),
plot_bgcolor='#e5ecf6',
xaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff'),
yaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff'))
fig