2016-05-30 32 views
1

基本上我想在圖表下面記下我的發現,例如「2000年到2006年間,病例增加了28%」。如何在圖表的底部添加註釋?

我已經嘗試過使用annotation_custom,但在facet_grid的情況下,它將它放在圖上的每個面之下,而不是完全在圖之外。我也嘗試在其他搜索上使用網格編排,但沒有文字甚至出現在我能看到的任何地方。

library(ggplot2) 
... 
graph <- ggplot(data=dataSource, aes(x=factor(year), y=Cases, fill = type)) 
graph <- graph+geom_bar(stat="identity")+facet_grid(.~type) 
graph <- graph+labs(title="Some title here", x="Year", y="Cases by county", fill="Type") 
print(graph) 
+0

代碼重複性。見[mcve]。 –

+0

在'ggplot2'的github版本中,在'labs()'中有一個新的'caption'選項, – hrbrmstr

回答

3

在cowplot包中使用add_sub。下面是從help("add_sub")範例章節的第一個例子:

library(ggplot2) 
library(cowplot) 

p1 <- ggplot(mtcars, aes(mpg, disp)) + 
     geom_line(colour = "blue") + 
     background_grid(minor='none') 
ggdraw(add_sub(p1, "This is an annotation.\nAnnotations can span multiple lines.")) 

screenshot

0

我沒有在做題應該看到一個問題grid.arrange

gridExtra::grid.arrange(ggplot(), bottom = "annotation here") 

enter image description here