Is there a way to add a data source / caption to a chart in Plotly, similar with what can be done in ggplot
with the caption argument:
labs(caption = "source: data i found somewhere")
i.e., so we can display the data source at the bottom right of the graph, in a smaller font.
In plotly, we can achieve a subtitle by adding some HTML formatting to the title string. We will Bold the title, emphasize it, add a line break, then use a span element with a reduced font size to add a subtitle. And that's it!
Standalone text annotations can be added to figures using fig. add_annotation() , with or without arrows, and they can be positioned absolutely within the figure, or they can be positioned relative to the axes of 2d or 3d cartesian subplots i.e. in data coordinates.
annotation
offers a simple way to add a caption to a chart in plotly
:
library(plotly)
plot_ly(x=~hp, y=~mpg, data=mtcars, type="scatter", mode="marker") %>%
layout(annotations =
list(x = 1, y = -0.1, text = "Source: data I found somewhere.",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=15, color="red"))
)
.
More details are given here and here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With