2016-05-30 132 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