将源或标题添加到图表中图表、标题

2023-09-06 08:13:37 作者:抬头就是阳光

有没有办法在 Plotly 中为图表添加数据源/标题,类似于在 ggplot 中可以使用标题参数完成的操作:

labs(caption = 来源:我在某处找到的数据")

也就是说,我们可以在图表的右下角以较小的字体显示数据源.

解决方案 word中公式与图表中怎样给图表加上标题

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.