2017-03-20 16 views
0

私のbarchartのバーにラベル(2016応答率)を追加しましたが、ラベルを個別/黒データポイント(2015応答レート)各バーの内側にあります。データポイントの第2セットに第2セットのラベルを追加する方法

enter image description here

これは私のコードです:

これを達成することができる方法
ggplot(merged2[merged2$TrustCode %in% acuteCodes, ], aes(x = TrustName, y = ResponseRate16)) + 
    geom_bar(fill="white",stat="identity", colour="blue") + 
    geom_point(aes(x = TrustName, y = ResponseRate15), shape=18, size=3, colour="black") + 
    geom_text(aes(label=ResponseRate16, x=TrustName, y=1.10*ResponseRate16), colour="black") 

?まさにあなたのような

答えて

1

はバー値がマッピングされた:私は少し繰り返しxマッピングのあなたのコードをクリーンアップgeom_text()

ggplot(merged2[merged2$TrustCode %in% acuteCodes, ], aes(x = TrustName, y = ResponseRate16)) + 
    geom_bar(fill = "white", stat = "identity", colour = "blue") + 
    geom_point(aes(y = ResponseRate15), shape = 18, size = 3, colour = "black") + 
    geom_text(aes(label = ResponseRate16, y = 1.10*ResponseRate16), colour="black") + 
    geom_text(aes(label = ResponseRate15, y = 1.10*ResponseRate15), colour="red") 

を追加します。すでに最初のggplot機能にマップされている場合はaestheticを複製する必要はありません。

新しいyを設定するのではなく、nudge_y argを使用することもできます。

ggplot(merged2[merged2$TrustCode %in% acuteCodes, ], aes(x = TrustName, y = ResponseRate16)) + 
     geom_bar(fill = "white", stat = "identity", colour = "blue") + 
     geom_text(aes(label = ResponseRate16), nudge_y = .5, colour="black") + 
     geom_point(aes(y = ResponseRate15), shape = 18, size = 3, colour = "black") + 
     geom_text(aes(label = ResponseRate15, y = ResponseRate15), nudge_y = .5, colour="red") 
+0

私はこれを試しましたが、間違って入力しているはずです(それはうまくいきません)ので、これは方法ではないと推測しました!私は休憩を取る時だと思う。 (そして、クリーンアップに感謝します!)あなたがここにいる間に、黒の数字を小数点以下2桁まで表示し、すべての数字にパーセンテージを追加する方法はありますか? – MusTheDataGuy

+0

おそらく、新しい 'y'の美しさを設定するのではなく、' nudge_y'引数を使いたいと思うかもしれません。その答えを編集する – GGamba

関連する問題