Adding footnote in Plotly

Viewed 321

I’m trying to add an asterisk footnote to a chart plotted with Plotly. This is my code:

library(plotly)

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

fig

Now I want to put an asterisk on "giraffes*" and after that give some additional explanation below this bar plot, let’s say: Note: * The tallest animal.

1 Answers

You can use layout(annotations) to add "caption" to 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')
  )

plotly caption

Related