有没有办法在 Plotly 中为图表添加数据源/标题,类似于在 ggplot
中可以使用标题参数完成的操作:
labs(caption = 来源:我在某处找到的数据")
也就是说,我们可以在图表的右下角以较小的字体显示数据源.
解决方案annotation
提供了一种在 plotly
中为图表添加标题的简单方法:
图书馆(情节)plot_ly(x=~hp, y=~mpg, data=mtcars, type="scatter", mode="marker") %>%布局(注释=list(x = 1, y = -0.1, text = "来源:我在某处找到的数据.",showarrow = F, xref='纸', yref='纸',xanchor='right', yanchor='auto', xshift=0, yshift=0,字体=列表(大小=15,颜色=红色")))
.
提供更多详细信息 这里和这里.p>
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.
解决方案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.