在 Plotly 中添加脚注

Adding footnote in Plotly

我正在尝试向使用 Plotly 绘制的图表添加星号脚注。这是我的代码:

library(plotly)

fig <- plot_ly(
  x = c("giraffes", "orangutans", "monkeys"),
  y = c(20, 14, 23),
  name = "SF Zoo",
  type = "bar"
)

fig

现在我想在“长颈鹿*”上加一个星号,然后在这个条形图下面给出一些额外的解释,比方说:Note: * The tallest animal.

您可以使用 layout(annotations)Plotly 添加“标题”。

library(plotly)

plot_ly(
  x = c("giraffes*", "orangutans", "monkeys"),
  y = c(20, 14, 23),
  name = "SF Zoo",
  type = "bar"
) |> 
  layout(annotations = 
           list(x = 0, y = -0.1, 
                text = "Note: * The tallest animal.", 
                showarrow = F, 
                xref='paper', 
                yref='paper')
  )