且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将源或标题添加到图表中

更新时间:2023-12-05 22:06:16

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.