내 ggplot 그래프의 각 막대에 숫자를 정렬하는 데 성공하지 못했습니다. 또 다른 문제는 범례 위에있는 "채우기"메시지를 제거하고 싶지만 어떻게 나타나는지 이해하지 못한다는 것입니다. 당신의 도움을 주셔서 감사합니다.
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) . 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] 삭제
몇 마디 만하겠습니다