누적 막대 차트를 만들려고하는데 채우기 순서가 설정된 수준을 따르지 않습니다. 이것은 만족도 조사 보고서이므로 막대 채우기의 특정 순서가 있어야합니다.
> head(dput(table.merged))
structure(list(value = structure(c(2L, 3L, 4L, 1L, 5L, 2L, 3L,
4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L,
1L, 5L, 2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L,
5L, 2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L,
2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L, 2L,
3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L), .Label = c("Very dissatisfied",
"Dissatisfied", "Neutral", "Satisfied", "Very satisfied"), class = "factor"),
site = c("Barcelona", "Barcelona", "Barcelona", "Barcelona",
"Barcelona", "Barcelona", "Barcelona", "Barcelona", "Barcelona",
"Barcelona", "Barcelona", "Barcelona", "Barcelona", "Barcelona",
"Barcelona", "Barcelona", "Barcelona", "Barcelona", "Barcelona",
"Barcelona", "Barcelona", "Barcelona", "Barcelona", "Barcelona",
"Barcelona", "Barcelona", "Barcelona", "Barcelona", "Barcelona",
"Barcelona", "Barcelona", "Barcelona", "Barcelona", "Barcelona",
"Barcelona", "Barcelona", "Barcelona", "Barcelona", "Barcelona",
"Barcelona", "Lisbon", "Lisbon", "Lisbon", "Lisbon", "Lisbon",
"Lisbon", "Lisbon", "Lisbon", "Lisbon", "Lisbon", "Lisbon",
"Lisbon", "Lisbon", "Lisbon", "Lisbon", "Lisbon", "Lisbon",
"Lisbon", "Lisbon", "Lisbon", "Lisbon", "Lisbon", "Lisbon",
"Lisbon", "Lisbon", "Lisbon", "Lisbon", "Lisbon", "Lisbon",
"Lisbon", "Lisbon", "Lisbon", "Lisbon", "Lisbon", "Lisbon",
"Lisbon", "Lisbon", "Lisbon", "Lisbon", "Lisbon"), variable = c("Is the TMS Team approachable ",
"Is the TMS Team approachable ", "Is the TMS Team approachable ",
"Is the TMS Team approachable ", "Is the TMS Team approachable ",
"They give you the chance to listen to your call ", "They give you the chance to listen to your call ",
"They give you the chance to listen to your call ", "They give you the chance to listen to your call ",
"They give you the chance to listen to your call ", "They fairly evaluate your calls ",
"They fairly evaluate your calls ", "They fairly evaluate your calls ",
"They fairly evaluate your calls ", "They fairly evaluate your calls ",
"They explain in detail the result of your call ", "They explain in detail the result of your call ",
"They explain in detail the result of your call ", "They explain in detail the result of your call ",
"They explain in detail the result of your call ", "They are knowledgeable about H2H ",
"They are knowledgeable about H2H ", "They are knowledgeable about H2H ",
"They are knowledgeable about H2H ", "They are knowledgeable about H2H ",
"They reinforce the 3As approach and importance ", "They reinforce the 3As approach and importance ",
"They reinforce the 3As approach and importance ", "They reinforce the 3As approach and importance ",
"They reinforce the 3As approach and importance ", "They give effective coaching to help you improve your NS results including H2H and 3As ",
"They give effective coaching to help you improve your NS results including H2H and 3As ",
"They give effective coaching to help you improve your NS results including H2H and 3As ",
"They give effective coaching to help you improve your NS results including H2H and 3As ",
"They give effective coaching to help you improve your NS results including H2H and 3As ",
"What is the overall satisfaction regarding the TMS Team ",
"What is the overall satisfaction regarding the TMS Team ",
"What is the overall satisfaction regarding the TMS Team ",
"What is the overall satisfaction regarding the TMS Team ",
"What is the overall satisfaction regarding the TMS Team ",
"Is the TMS Team approachable ", "Is the TMS Team approachable ",
"Is the TMS Team approachable ", "Is the TMS Team approachable ",
"Is the TMS Team approachable ", "They give you the chance to listen to your call ",
"They give you the chance to listen to your call ", "They give you the chance to listen to your call ",
"They give you the chance to listen to your call ", "They give you the chance to listen to your call ",
"They fairly evaluate your calls ", "They fairly evaluate your calls ",
"They fairly evaluate your calls ", "They fairly evaluate your calls ",
"They fairly evaluate your calls ", "They explain in detail the result of your call ",
"They explain in detail the result of your call ", "They explain in detail the result of your call ",
"They explain in detail the result of your call ", "They explain in detail the result of your call ",
"They are knowledgeable about H2H ", "They are knowledgeable about H2H ",
"They are knowledgeable about H2H ", "They are knowledgeable about H2H ",
"They are knowledgeable about H2H ", "They reinforce the 3As approach and importance ",
"They reinforce the 3As approach and importance ", "They reinforce the 3As approach and importance ",
"They reinforce the 3As approach and importance ", "They reinforce the 3As approach and importance ",
"They give effective coaching to help you improve your NS results including H2H and 3As ",
"They give effective coaching to help you improve your NS results including H2H and 3As ",
"They give effective coaching to help you improve your NS results including H2H and 3As ",
"They give effective coaching to help you improve your NS results including H2H and 3As ",
"They give effective coaching to help you improve your NS results including H2H and 3As ",
"What is the overall satisfaction regarding the TMS Team ",
"What is the overall satisfaction regarding the TMS Team ",
"What is the overall satisfaction regarding the TMS Team ",
"What is the overall satisfaction regarding the TMS Team ",
"What is the overall satisfaction regarding the TMS Team "
), score = c(0.0431034482758621, 0.129310344827586, 0.413793103448276,
0.0258620689655172, 0.387931034482759, 0.0431034482758621,
0.293103448275862, 0.310344827586207, 0.0603448275862069,
0.293103448275862, 0.0603448275862069, 0.198275862068966,
0.387931034482759, 0.0431034482758621, 0.310344827586207,
0.0172413793103448, 0.155172413793103, 0.413793103448276,
0.0258620689655172, 0.387931034482759, 0.0258620689655172,
0.103448275862069, 0.379310344827586, 0.0258620689655172,
0.46551724137931, 0.0172413793103448, 0.0948275862068965,
0.336206896551724, 0.0258620689655172, 0.525862068965517,
0.0344827586206897, 0.146551724137931, 0.318965517241379,
0.0344827586206897, 0.46551724137931, 0.0344827586206897,
0.181034482758621, 0.336206896551724, 0.0258620689655172,
0.422413793103448, 0.0628930817610063, 0.270440251572327,
0.383647798742138, 0.0377358490566038, 0.245283018867925,
0.119496855345912, 0.364779874213836, 0.232704402515723,
0.10062893081761, 0.182389937106918, 0.0880503144654088,
0.19496855345912, 0.446540880503145, 0.0314465408805031,
0.238993710691824, 0.0691823899371069, 0.138364779874214,
0.452830188679245, 0.0251572327044025, 0.314465408805031,
0.0314465408805031, 0.182389937106918, 0.427672955974843,
0.0251572327044025, 0.333333333333333, 0.0377358490566038,
0.132075471698113, 0.427672955974843, 0.0125786163522013,
0.389937106918239, 0.0566037735849057, 0.207547169811321,
0.364779874213836, 0.050314465408805, 0.320754716981132,
0.0628930817610063, 0.19496855345912, 0.408805031446541,
0.0440251572327044, 0.289308176100629), Position = c(0.021551724137931,
0.107758620689655, 0.379310344827586, 0.599137931034483,
0.806034482758621, 0.021551724137931, 0.189655172413793,
0.491379310344828, 0.676724137931034, 0.853448275862069,
0.0301724137931034, 0.15948275862069, 0.452586206896552,
0.668103448275862, 0.844827586206897, 0.00862068965517241,
0.0948275862068966, 0.379310344827586, 0.599137931034483,
0.806034482758621, 0.0129310344827586, 0.0775862068965517,
0.318965517241379, 0.521551724137931, 0.767241379310345,
0.00862068965517241, 0.0646551724137931, 0.280172413793103,
0.461206896551724, 0.737068965517241, 0.0172413793103448,
0.107758620689655, 0.34051724137931, 0.517241379310345, 0.767241379310345,
0.0172413793103448, 0.125, 0.383620689655172, 0.564655172413793,
0.788793103448276, 0.0314465408805031, 0.19811320754717,
0.525157232704403, 0.735849056603774, 0.877358490566038,
0.059748427672956, 0.30188679245283, 0.60062893081761, 0.767295597484277,
0.908805031446541, 0.0440251572327044, 0.185534591194969,
0.506289308176101, 0.745283018867925, 0.880503144654088,
0.0345911949685535, 0.138364779874214, 0.433962264150943,
0.672955974842767, 0.842767295597484, 0.0157232704402516,
0.122641509433962, 0.427672955974843, 0.654088050314465,
0.833333333333333, 0.0188679245283019, 0.10377358490566,
0.383647798742138, 0.60377358490566, 0.805031446540881, 0.0283018867924528,
0.160377358490566, 0.446540880503145, 0.654088050314465,
0.839622641509434, 0.0314465408805031, 0.160377358490566,
0.462264150943396, 0.688679245283019, 0.855345911949686),
variable2 = c("Is the TMS Team\napproachable", "Is the TMS Team\napproachable",
"Is the TMS Team\napproachable", "Is the TMS Team\napproachable",
"Is the TMS Team\napproachable", "They give you\nthe chance to\nlisten to your\ncall",
"They give you\nthe chance to\nlisten to your\ncall", "They give you\nthe chance to\nlisten to your\ncall",
"They give you\nthe chance to\nlisten to your\ncall", "They give you\nthe chance to\nlisten to your\ncall",
"They fairly\nevaluate your\ncalls", "They fairly\nevaluate your\ncalls",
"They fairly\nevaluate your\ncalls", "They fairly\nevaluate your\ncalls",
"They fairly\nevaluate your\ncalls", "They explain\nin detail the\nresult of your\ncall",
"They explain\nin detail the\nresult of your\ncall", "They explain\nin detail the\nresult of your\ncall",
"They explain\nin detail the\nresult of your\ncall", "They explain\nin detail the\nresult of your\ncall",
"They are\nknowledgeable\nabout H2H", "They are\nknowledgeable\nabout H2H",
"They are\nknowledgeable\nabout H2H", "They are\nknowledgeable\nabout H2H",
"They are\nknowledgeable\nabout H2H", "They reinforce\nthe 3As\napproach and\nimportance",
"They reinforce\nthe 3As\napproach and\nimportance", "They reinforce\nthe 3As\napproach and\nimportance",
"They reinforce\nthe 3As\napproach and\nimportance", "They reinforce\nthe 3As\napproach and\nimportance",
"They give\neffective\ncoaching\nto help you\nimprove your\nNS results\nincluding H2H\nand 3As",
"They give\neffective\ncoaching\nto help you\nimprove your\nNS results\nincluding H2H\nand 3As",
"They give\neffective\ncoaching\nto help you\nimprove your\nNS results\nincluding H2H\nand 3As",
"They give\neffective\ncoaching\nto help you\nimprove your\nNS results\nincluding H2H\nand 3As",
"They give\neffective\ncoaching\nto help you\nimprove your\nNS results\nincluding H2H\nand 3As",
"What is\nthe overall\nsatisfaction\nregarding the\nTMS Team",
"What is\nthe overall\nsatisfaction\nregarding the\nTMS Team",
"What is\nthe overall\nsatisfaction\nregarding the\nTMS Team",
"What is\nthe overall\nsatisfaction\nregarding the\nTMS Team",
"What is\nthe overall\nsatisfaction\nregarding the\nTMS Team",
"Is the TMS Team\napproachable", "Is the TMS Team\napproachable",
"Is the TMS Team\napproachable", "Is the TMS Team\napproachable",
"Is the TMS Team\napproachable", "They give you\nthe chance to\nlisten to your\ncall",
"They give you\nthe chance to\nlisten to your\ncall", "They give you\nthe chance to\nlisten to your\ncall",
"They give you\nthe chance to\nlisten to your\ncall", "They give you\nthe chance to\nlisten to your\ncall",
"They fairly\nevaluate your\ncalls", "They fairly\nevaluate your\ncalls",
"They fairly\nevaluate your\ncalls", "They fairly\nevaluate your\ncalls",
"They fairly\nevaluate your\ncalls", "They explain\nin detail the\nresult of your\ncall",
"They explain\nin detail the\nresult of your\ncall", "They explain\nin detail the\nresult of your\ncall",
"They explain\nin detail the\nresult of your\ncall", "They explain\nin detail the\nresult of your\ncall",
"They are\nknowledgeable\nabout H2H", "They are\nknowledgeable\nabout H2H",
"They are\nknowledgeable\nabout H2H", "They are\nknowledgeable\nabout H2H",
"They are\nknowledgeable\nabout H2H", "They reinforce\nthe 3As\napproach and\nimportance",
"They reinforce\nthe 3As\napproach and\nimportance", "They reinforce\nthe 3As\napproach and\nimportance",
"They reinforce\nthe 3As\napproach and\nimportance", "They reinforce\nthe 3As\napproach and\nimportance",
"They give\neffective\ncoaching\nto help you\nimprove your\nNS results\nincluding H2H\nand 3As",
"They give\neffective\ncoaching\nto help you\nimprove your\nNS results\nincluding H2H\nand 3As",
"They give\neffective\ncoaching\nto help you\nimprove your\nNS results\nincluding H2H\nand 3As",
"They give\neffective\ncoaching\nto help you\nimprove your\nNS results\nincluding H2H\nand 3As",
"They give\neffective\ncoaching\nto help you\nimprove your\nNS results\nincluding H2H\nand 3As",
"What is\nthe overall\nsatisfaction\nregarding the\nTMS Team",
"What is\nthe overall\nsatisfaction\nregarding the\nTMS Team",
"What is\nthe overall\nsatisfaction\nregarding the\nTMS Team",
"What is\nthe overall\nsatisfaction\nregarding the\nTMS Team",
"What is\nthe overall\nsatisfaction\nregarding the\nTMS Team"
)), .Names = c("value", "site", "variable", "score", "Position",
"variable2"), row.names = c(NA, 80L), vars = list(variable), labels = structure(list(
variable = structure(1:8, .Label = c("Is.the.TMS.Team.approachable.",
"They.give.you.the.chance.to.listen.to.your.call.", "They.fairly.evaluate.your.calls.",
"They.explain.in.detail.the.result.of.your.call.", "They.are.knowledgeable.about.H2H.",
"They.reinforce.the.3As.approach.and.importance.", "They.give.effective.coaching.to.help.you.improve.your.NS.results..including.H2H.and.3As.",
"What.is.the.overall.satisfaction.regarding.the.TMS.Team.."
), class = "factor")), class = "data.frame", row.names = c(NA,
-8L), .Names = "variable", vars = list(variable)), indices = list(
0:4, 5:9, 10:14, 15:19, 20:24, 25:29, 30:34, 35:39), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
다음은 ggplot 코드입니다.
ggplot(table.merged,aes(variable2,score,fill=value))+
geom_bar(stat="identity",alpha=0.6,colour="grey60")+
geom_text(aes(label=round(score,2),y=table.merged$Position),colour="white")+
facet_wrap(~site)+
scale_fill_manual(values=c("darkred","red","orange","green","darkgreen"))+
labs(title="General satisfaction with TMS", y="Percentage",x="")+
theme(plot.title=element_text(vjust=1),
legend.position="top",
legend.title=element_blank())
막대가 레벨 대신 알파벳순으로 채워지는 것을 볼 수 있습니다. 나는 order
ggplot aes에서 사용하려고 시도 했으며이 문제를 해결했지만 geom_text가 잘못 정렬되어 문제가 발생합니다.
당신의 도움을 주셔서 감사합니다!
가장 쉬운 수정 방법은 Position
막대를 원하는 순서와 일치 하도록 변수 를 계산하는 것 입니다. 위치는 누적 합계를 기반으로 할 가능성이 높기 때문에 그룹 내에서 순서를 설정하지 않으면 텍스트가 스택의 순서.
여기서는 dplyr의 함수를 사용하여 위치를 계산합니다 . 나는 arrange
당신이 이미 설정 한 요인 수준에 따라 정렬하는 데 사용 합니다.
library(dplyr)
table.merged2 = table.merged %>%
group_by(site, variable2) %>%
arrange(value) %>%
mutate(position2 = cumsum(score) - (0.5 * score))
새 데이터 세트를 사용하면 채우기가 순서대로 정렬되고 value
레이블과 스택이 올바른 위치에 있습니다 (내 눈에는 일치하는 것 같습니다).
ggplot(table.merged2, aes(variable2, score, fill=value)) +
geom_bar(stat="identity",alpha=0.6,colour="grey60") +
geom_text(aes(label=round(score,2), y=position2), colour="white") +
facet_wrap(~site) +
scale_fill_manual(values=c("darkred","red","orange","green","darkgreen")) +
labs(title="General satisfaction with TMS", y="Percentage", x="") +
theme(plot.title=element_text(vjust=1),
legend.position="top",
legend.title=element_blank())
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다