2016-05-30 14 views
1

基本的には、「2000年から2006年の間に症例が28%増加しました」などのグラフの下に自分の所見を書き留めたいと思います。グラフの下部にアノテーションを追加するにはどうすればよいですか?

私はannotation_customを使用しようとしましたが、facet_gridの場合、グラフの各ファセットの下にそれをグラフの領域の外側に置きます。私はまた、SOの他の検索からのグリッドアレンジを使用しようとしましたが、テキストが表示されていてもどこにも表示されません。

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

のgithubバージョンの 'ggplot2'に' labs() 'に新しい' caption'オプションがあります – hrbrmstr

答えて

3

カウプロットパッケージに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

私はSOの質問でgrid.arrange

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

enter image description here

関連する問題