2017-07-14 96 views
1

有沒有辦法到數據源/字幕添加到Plotly圖表,用什麼可以在ggplot完成的文字說明論點相似:plotly添加源或標題爲圖表

labs(caption = "source: data i found somewhere") 

即,所以我們可以以較小的字體顯示圖表右下角的數據源。

回答

1

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")) 
) 

enter image description here

更多細節給出herehere

+0

感謝Marco,但ggplot已經有實驗室了。我的問題是專門做這件事,但情節劇本。 – chrisjacques

+0

@chrisjacques我編輯了我的答案。現在你可以找到一種方法來爲你的圖表添加一個標題。如果此解決方案可以幫助您,請考慮放棄它。 –