我想知道如何使用plot_ly为子图提供不同的字幕。请提示任何提示。在这种情况下我得到了一个BB冠军。谢谢。
p <- subplot(
plot_ly(economics, x = date, y = uempmed)%>%layout(showlegend = FALSE, title="AA"),
plot_ly(economics, x = date, y = unemploy)%>%layout(showlegend = FALSE, title="BB"),
margin = 0.05
)
该 title
布局中的属性是指整个绘图表面的标题,因此只能有一个。但是,我们可以使用文本注释为子图创建“标题”,例如:
p <- subplot(
plot_ly(economics, x = date, y = uempmed)%>%layout(showlegend = FALSE),
plot_ly(economics, x = date, y = unemploy)%>%layout(showlegend = FALSE),
margin = 0.05
)
p %>% layout(annotations = list(
list(x = 0.2 , y = 1.05, text = "AA", showarrow = F, xref='paper', yref='paper'),
list(x = 0.8 , y = 1.05, text = "BB", showarrow = F, xref='paper', yref='paper'))
)
您现在可以利用,而不是“手动”定位(即@ d-roy的答案) subplot()
能够重新定位纸张引用的东西,如注释(以及形状,图像等)。
library(plotly)
library(dplyr)
my_plot <- . %>%
plot_ly(x = ~date, y = ~value) %>%
add_annotations(
text = ~unique(variable),
x = 0.5,
y = 1,
yref = "paper",
xref = "paper",
xanchor = "middle",
yanchor = "top",
showarrow = FALSE,
font = list(size = 15)
)
economics_long %>%
group_by(variable) %>%
do(p = my_plot(.)) %>%
subplot(nrows = NROW(.), shareX = TRUE)
该 title
布局中的属性是指整个绘图表面的标题,因此只能有一个。但是,我们可以使用文本注释为子图创建“标题”,例如:
p <- subplot(
plot_ly(economics, x = date, y = uempmed)%>%layout(showlegend = FALSE),
plot_ly(economics, x = date, y = unemploy)%>%layout(showlegend = FALSE),
margin = 0.05
)
p %>% layout(annotations = list(
list(x = 0.2 , y = 1.05, text = "AA", showarrow = F, xref='paper', yref='paper'),
list(x = 0.8 , y = 1.05, text = "BB", showarrow = F, xref='paper', yref='paper'))
)
您现在可以利用,而不是“手动”定位(即@ d-roy的答案) subplot()
能够重新定位纸张引用的东西,如注释(以及形状,图像等)。
library(plotly)
library(dplyr)
my_plot <- . %>%
plot_ly(x = ~date, y = ~value) %>%
add_annotations(
text = ~unique(variable),
x = 0.5,
y = 1,
yref = "paper",
xref = "paper",
xanchor = "middle",
yanchor = "top",
showarrow = FALSE,
font = list(size = 15)
)
economics_long %>%
group_by(variable) %>%
do(p = my_plot(.)) %>%
subplot(nrows = NROW(.), shareX = TRUE)