问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/45103559/plotly-adding-a-source-or-caption-to-a-chart