ggplotグラフの各バーに数値を合わせることができません。もう1つの問題は、凡例の上にある「塗りつぶし」というメッセージを削除したいのですが、どのように表示されたかわかりません。ご協力いただきありがとうございます。
graph <- ggplot(df, aes(x=labs)) +
geom_bar(data=df[df$isEmotion=="emotion",], aes(y=RTU, fill = "Emotion"), stat="identity") +
geom_bar(data=df[df$isEmotion=="no emotion",], aes(y=-RTU, fill = "No Emotion"), stat="identity") +
geom_hline(yintercept=0, colour="white", lwd=1) +
theme(text = element_text(size=15)) +
coord_flip(ylim=lim) +
scale_y_continuous(breaks=breaks, labels=labels) +
labs(y="RTU", x="Collaborative acts") +
ggtitle(" Interested") +
geom_text(aes(label = round(RTU), y=RTU))
lim = c(-1.6,1.6)
breaks = seq(-1.6,1.6,0.4)
labels = c(1.6,1.2,0.8,0.4,0,0.4,0.8,1.2,1.6)
経由のデータテーブルdput
:
structure(list(labs = structure(c(29L, 28L, 27L, 26L, 25L, 24L,
23L, 22L, 21L, 20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L,
10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 29L, 28L, 27L, 26L,
25L, 24L, 23L, 22L, 21L, 20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L,
12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L), .Label = c("Show Hostility",
"Elicit Recall", "Check Comprehension", "Refuse", "Show Solidarity",
"Give Explanation", "Elicit Proposition", "Incorporate", "Use Social Convention",
"Elicit Partner Information", "Outside Activity", "Give Opinion Against",
"Coordinate Teamwork", "Check Reception", "Elicit Task Information",
"Show Active Listening", "Elicit Opinion", "Give Recall", "Give Task Information",
"Give Self Information", "Relax Atmosphere", "Manage Task", "Give Proposition",
"Tool Discourse", "Show Reflection", "Accept", "Agree", "Other",
"Give Opinion For"), class = "factor"), RTU = c(1.33679949277407,
1.113629906839, 0.998523521750659, 0.774259935575577, 0.659963240986954,
0.60839106356628, 0.6065649859483, 0.539489093267195, 0.480274995783261,
0.423104935724923, 0.408927591199088, 0.274223979504919, 0.270110544387821,
0.258935589229039, 0.218353068762815, 0.193643374161986, 0.177004182065326,
0.102980320541176, 0.0980838299538663, 0.0969015258673401, 0.0734178878735949,
0.0649985993746002, 0.054594994045725, 0.0404505716411595, 0.0345846135809401,
0.0344802024462216, 0.0311026889658307, 0.0245605273402327, 0.00164473684210526,
0.798245614035088, 0.631578947368421, 0.87719298245614, 1.21052631578947,
0.657894736842105, 0.526315789473684, 0.56140350877193, 0.508771929824561,
0.543859649122807, 0.473684210526316, 0.587719298245614, 0.236842105263158,
0.254385964912281, 0.333333333333333, 0.280701754385965, 0.368421052631579,
0.333333333333333, 0.175438596491228, 0.0175438596491228, 0.0701754385964912,
0.184210526315789, 0.0175438596491228, 0.114035087719298, 0.0789473684210526,
0, 0, 0.105263157894737, 0.0526315789473684, 0), isEmotion = c("no emotion",
"no emotion", "no emotion", "no emotion", "no emotion", "no emotion",
"no emotion", "no emotion", "no emotion", "no emotion", "no emotion",
"no emotion", "no emotion", "no emotion", "no emotion", "no emotion",
"no emotion", "no emotion", "no emotion", "no emotion", "no emotion",
"no emotion", "no emotion", "no emotion", "no emotion", "no emotion",
"no emotion", "no emotion", "no emotion", "emotion", "emotion",
"emotion", "emotion", "emotion", "emotion", "emotion", "emotion",
"emotion", "emotion", "emotion", "emotion", "emotion", "emotion",
"emotion", "emotion", "emotion", "emotion", "emotion", "emotion",
"emotion", "emotion", "emotion", "emotion", "emotion", "emotion",
"emotion", "emotion", "emotion")), row.names = c(NA, -58L), class = "data.frame")
凡例のタイトルを削除するには、関数を使用できますlabs(fill = "")
。geom_barの場合と同様に、ピラミッドのラベルを揃えるにgeom_text
は、グループのラベルemotion
(およびy = RTU)用とグループのラベルno emotion
(y = -RTU)用の2行を渡す必要があります。。hjust
それらのそれぞれを調整して、プロット上できれいにすることができます。
ggplot(df, aes(x = labs)) +
geom_bar(data = ~subset(., isEmotion=="emotion"), aes( y = RTU, fill = "Emotion"), stat = "identity") +
geom_bar(data = ~subset(., isEmotion=="no emotion"), aes(y = -RTU, fill = "No Emotion"), stat = "identity") +
geom_hline(yintercept=0, colour="white", lwd=1) +
theme(text = element_text(size=15)) +
coord_flip(ylim=lim) +
scale_y_continuous(breaks=breaks, labels=labels) +
labs(y="RTU", x="Collaborative acts") +
ggtitle(" Interested") +
geom_text(data = ~subset(., isEmotion=="emotion"), aes(label = round(RTU, digits = 2), y = RTU), hjust = -0.75) +
geom_text(data = ~subset(., isEmotion=="no emotion"), aes(label = round(RTU, digits = 2), y = -RTU), hjust = 1.5)+
labs(fill = "")
それがあなたの質問に答えることを願っています!
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加