剧情地向图表添加源或标题

chr*_*ues 5 r plotly

有没有一种方法可以将数据源/标题添加到Plotly中的图表,类似于可以ggplot使用caption参数完成的操作:

labs(caption = "source: data i found somewhere") 
Run Code Online (Sandbox Code Playgroud)

即,因此我们可以将数据源以较小的字体显示在图的右下方。

Mar*_*dri 9

annotation提供了一种简单的方法来向以下图表添加标题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"))
 )
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

这里这里都给出更多细节。