2017-11-07 16 views
1

私は折れ線グラフの凡例を追加したい積み重ねグラフと折れ線グラフ表示伝説 - 積み上げ棒とライン

ggplot() + 
     geom_bar(data=smr2, aes(x=Pract, y=value, fill=variable), stat='identity') + 
     theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) + 
     geom_line(data=summarised[,1:3], aes(x=Pract,y=YTDTarget, group=1),size = 1) + 
     geom_point(data=summarised[,1:3], mapping = aes(x = Pract, y = YTDTarget),size=2.5)+ 
     geom_text_repel(data=summarised[,1:3], aes(x=Pract,y=YTDTarget,label=YTDTarget), size = 5) 

の組み合わせですggplotを、持っています。しかし、部分group=1はこれを防ぐようです。

私が作成したグラフは、enter image description here

ようである。また、実際に達成(スタックバーに対してターゲット(折れ線グラフ)を比較するためにこのグラフは「実績」 に変数から伝説の名前を変更するには助けてください)。

答えて

3

これを試してください:geom_line

は(伝説に追加する - この場合には、私はlinetypeを使用しています)ダミー変数を追加します。

geom_line(data = summarised[,1:3], 
      aes(Pract, YTDTarget, group = 1, linetype = ""), 
      size = 1) 

凡例の名前を変更するには、プロットにlabs()を追加します。

labs(fill = "Actuals", 
    linetype = "My Line Name") 
関連する問題