{"action":"created","issue":{"url":"https://api.github.com/repos/hadley/ggplot2/issues/1301","labels_url":"https://api.github.com/repos/hadley/ggplot2/issues/1301/labels{/name}","comments_url":"https://api.github.com/repos/hadley/ggplot2/issues/1301/comments","events_url":"https://api.github.com/repos/hadley/ggplot2/issues/1301/events","html_url":"https://github.com/hadley/ggplot2/issues/1301","id":103770542,"number":1301,"title":"geom_bar fill ignores order of factor's levels.","user":{"login":"DasHammett","id":13760961,"avatar_url":"https://avatars.githubusercontent.com/u/13760961?v=3","gravatar_id":"","url":"https://api.github.com/users/DasHammett","html_url":"https://github.com/DasHammett","followers_url":"https://api.github.com/users/DasHammett/followers","following_url":"https://api.github.com/users/DasHammett/following{/other_user}","gists_url":"https://api.github.com/users/DasHammett/gists{/gist_id}","starred_url":"https://api.github.com/users/DasHammett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DasHammett/subscriptions","organizations_url":"https://api.github.com/users/DasHammett/orgs","repos_url":"https://api.github.com/users/DasHammett/repos","events_url":"https://api.github.com/users/DasHammett/events{/privacy}","received_events_url":"https://api.github.com/users/DasHammett/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-08-28T18:18:15Z","updated_at":"2015-08-29T19:45:44Z","closed_at":"2015-08-29T11:29:54Z","body":"Hi!\r\n\r\nI am having an issue with geom_bar when I pass the fill parameter to ggplot aes. The order of filling is done alphabetically, ignoring the levels.\r\n\r\nI have tried to pass ```order``` parameter to ggplot aes and it solves the issue, but then geom_text is misaligned.\r\n\r\nOn a side note, Positions for geom_text are done after leveling is set.\r\n\r\nI share a ```head``` of the dput for reproducibility purposes. This is a sample of a satisfaction survey, hence the importance of having the correct order of filling up the bars.\r\n```\r\nstructure(list(value = structure(c(2L, 3L, 4L, 1L, 5L, 2L, 3L, \r\n4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L, \r\n1L, 5L, 2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L, \r\n5L, 2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L, \r\n2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L, 2L, \r\n3L, 4L, 1L, 5L, 2L, 3L, 4L, 1L, 5L), .Label = c(\"Very dissatisfied\", \r\n\"Dissatisfied\", \"Neutral\", \"Satisfied\", \"Very satisfied\"), class = \"factor\"), \r\n    site = c(\"Barcelona\", \"Barcelona\", \"Barcelona\", \"Barcelona\", \r\n    \"Barcelona\", \"Barcelona\", \"Barcelona\", \"Barcelona\", \"Barcelona\", \r\n    \"Barcelona\", \"Barcelona\", \"Barcelona\", \"Barcelona\", \"Barcelona\", \r\n    \"Barcelona\", \"Barcelona\", \"Barcelona\", \"Barcelona\", \"Barcelona\", \r\n    \"Barcelona\", \"Barcelona\", \"Barcelona\", \"Barcelona\", \"Barcelona\", \r\n    \"Barcelona\", \"Barcelona\", \"Barcelona\", \"Barcelona\", \"Barcelona\", \r\n    \"Barcelona\", \"Barcelona\", \"Barcelona\", \"Barcelona\", \"Barcelona\", \r\n    \"Barcelona\", \"Barcelona\", \"Barcelona\", \"Barcelona\", \"Barcelona\", \r\n    \"Barcelona\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \r\n    \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \r\n    \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \r\n    \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \r\n    \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \r\n    \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \r\n    \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\", \"Lisbon\"), variable = c(\"Is the TMS Team approachable \", \r\n    \"Is the TMS Team approachable \", \"Is the TMS Team approachable \", \r\n    \"Is the TMS Team approachable \", \"Is the TMS Team approachable \", \r\n    \"They give you the chance to listen to your call \", \"They give you the chance to listen to your call \", \r\n    \"They give you the chance to listen to your call \", \"They give you the chance to listen to your call \", \r\n    \"They give you the chance to listen to your call \", \"They fairly evaluate your calls \", \r\n    \"They fairly evaluate your calls \", \"They fairly evaluate your calls \", \r\n    \"They fairly evaluate your calls \", \"They fairly evaluate your calls \", \r\n    \"They explain in detail the result of your call \", \"They explain in detail the result of your call \", \r\n    \"They explain in detail the result of your call \", \"They explain in detail the result of your call \", \r\n    \"They explain in detail the result of your call \", \"They are knowledgeable about H2H \", \r\n    \"They are knowledgeable about H2H \", \"They are knowledgeable about H2H \", \r\n    \"They are knowledgeable about H2H \", \"They are knowledgeable about H2H \", \r\n    \"They reinforce the 3As approach and importance \", \"They reinforce the 3As approach and importance \", \r\n    \"They reinforce the 3As approach and importance \", \"They reinforce the 3As approach and importance \", \r\n    \"They reinforce the 3As approach and importance \", \"They give effective coaching to help you improve your NS results  including H2H and 3As \", \r\n    \"They give effective coaching to help you improve your NS results  including H2H and 3As \", \r\n    \"They give effective coaching to help you improve your NS results  including H2H and 3As \", \r\n    \"They give effective coaching to help you improve your NS results  including H2H and 3As \", \r\n    \"They give effective coaching to help you improve your NS results  including H2H and 3As \", \r\n    \"What is the overall satisfaction regarding the TMS Team  \", \r\n    \"What is the overall satisfaction regarding the TMS Team  \", \r\n    \"What is the overall satisfaction regarding the TMS Team  \", \r\n    \"What is the overall satisfaction regarding the TMS Team  \", \r\n    \"What is the overall satisfaction regarding the TMS Team  \", \r\n    \"Is the TMS Team approachable \", \"Is the TMS Team approachable \", \r\n    \"Is the TMS Team approachable \", \"Is the TMS Team approachable \", \r\n    \"Is the TMS Team approachable \", \"They give you the chance to listen to your call \", \r\n    \"They give you the chance to listen to your call \", \"They give you the chance to listen to your call \", \r\n    \"They give you the chance to listen to your call \", \"They give you the chance to listen to your call \", \r\n    \"They fairly evaluate your calls \", \"They fairly evaluate your calls \", \r\n    \"They fairly evaluate your calls \", \"They fairly evaluate your calls \", \r\n    \"They fairly evaluate your calls \", \"They explain in detail the result of your call \", \r\n    \"They explain in detail the result of your call \", \"They explain in detail the result of your call \", \r\n    \"They explain in detail the result of your call \", \"They explain in detail the result of your call \", \r\n    \"They are knowledgeable about H2H \", \"They are knowledgeable about H2H \", \r\n    \"They are knowledgeable about H2H \", \"They are knowledgeable about H2H \", \r\n    \"They are knowledgeable about H2H \", \"They reinforce the 3As approach and importance \", \r\n    \"They reinforce the 3As approach and importance \", \"They reinforce the 3As approach and importance \", \r\n    \"They reinforce the 3As approach and importance \", \"They reinforce the 3As approach and importance \", \r\n    \"They give effective coaching to help you improve your NS results  including H2H and 3As \", \r\n    \"They give effective coaching to help you improve your NS results  including H2H and 3As \", \r\n    \"They give effective coaching to help you improve your NS results  including H2H and 3As \", \r\n    \"They give effective coaching to help you improve your NS results  including H2H and 3As \", \r\n    \"They give effective coaching to help you improve your NS results  including H2H and 3As \", \r\n    \"What is the overall satisfaction regarding the TMS Team  \", \r\n    \"What is the overall satisfaction regarding the TMS Team  \", \r\n    \"What is the overall satisfaction regarding the TMS Team  \", \r\n    \"What is the overall satisfaction regarding the TMS Team  \", \r\n    \"What is the overall satisfaction regarding the TMS Team  \"\r\n    ), score = c(0.0431034482758621, 0.129310344827586, 0.413793103448276, \r\n    0.0258620689655172, 0.387931034482759, 0.0431034482758621, \r\n    0.293103448275862, 0.310344827586207, 0.0603448275862069, \r\n    0.293103448275862, 0.0603448275862069, 0.198275862068966, \r\n    0.387931034482759, 0.0431034482758621, 0.310344827586207, \r\n    0.0172413793103448, 0.155172413793103, 0.413793103448276, \r\n    0.0258620689655172, 0.387931034482759, 0.0258620689655172, \r\n    0.103448275862069, 0.379310344827586, 0.0258620689655172, \r\n    0.46551724137931, 0.0172413793103448, 0.0948275862068965, \r\n    0.336206896551724, 0.0258620689655172, 0.525862068965517, \r\n    0.0344827586206897, 0.146551724137931, 0.318965517241379, \r\n    0.0344827586206897, 0.46551724137931, 0.0344827586206897, \r\n    0.181034482758621, 0.336206896551724, 0.0258620689655172, \r\n    0.422413793103448, 0.0628930817610063, 0.270440251572327, \r\n    0.383647798742138, 0.0377358490566038, 0.245283018867925, \r\n    0.119496855345912, 0.364779874213836, 0.232704402515723, \r\n    0.10062893081761, 0.182389937106918, 0.0880503144654088, \r\n    0.19496855345912, 0.446540880503145, 0.0314465408805031, \r\n    0.238993710691824, 0.0691823899371069, 0.138364779874214, \r\n    0.452830188679245, 0.0251572327044025, 0.314465408805031, \r\n    0.0314465408805031, 0.182389937106918, 0.427672955974843, \r\n    0.0251572327044025, 0.333333333333333, 0.0377358490566038, \r\n    0.132075471698113, 0.427672955974843, 0.0125786163522013, \r\n    0.389937106918239, 0.0566037735849057, 0.207547169811321, \r\n    0.364779874213836, 0.050314465408805, 0.320754716981132, \r\n    0.0628930817610063, 0.19496855345912, 0.408805031446541, \r\n    0.0440251572327044, 0.289308176100629), Position = c(0.021551724137931, \r\n    0.107758620689655, 0.379310344827586, 0.599137931034483, \r\n    0.806034482758621, 0.021551724137931, 0.189655172413793, \r\n    0.491379310344828, 0.676724137931034, 0.853448275862069, \r\n    0.0301724137931034, 0.15948275862069, 0.452586206896552, \r\n    0.668103448275862, 0.844827586206897, 0.00862068965517241, \r\n    0.0948275862068966, 0.379310344827586, 0.599137931034483, \r\n    0.806034482758621, 0.0129310344827586, 0.0775862068965517, \r\n    0.318965517241379, 0.521551724137931, 0.767241379310345, \r\n    0.00862068965517241, 0.0646551724137931, 0.280172413793103, \r\n    0.461206896551724, 0.737068965517241, 0.0172413793103448, \r\n    0.107758620689655, 0.34051724137931, 0.517241379310345, 0.767241379310345, \r\n    0.0172413793103448, 0.125, 0.383620689655172, 0.564655172413793, \r\n    0.788793103448276, 0.0314465408805031, 0.19811320754717, \r\n    0.525157232704403, 0.735849056603774, 0.877358490566038, \r\n    0.059748427672956, 0.30188679245283, 0.60062893081761, 0.767295597484277, \r\n    0.908805031446541, 0.0440251572327044, 0.185534591194969, \r\n    0.506289308176101, 0.745283018867925, 0.880503144654088, \r\n    0.0345911949685535, 0.138364779874214, 0.433962264150943, \r\n    0.672955974842767, 0.842767295597484, 0.0157232704402516, \r\n    0.122641509433962, 0.427672955974843, 0.654088050314465, \r\n    0.833333333333333, 0.0188679245283019, 0.10377358490566, \r\n    0.383647798742138, 0.60377358490566, 0.805031446540881, 0.0283018867924528, \r\n    0.160377358490566, 0.446540880503145, 0.654088050314465, \r\n    0.839622641509434, 0.0314465408805031, 0.160377358490566, \r\n    0.462264150943396, 0.688679245283019, 0.855345911949686), \r\n    variable2 = c(\"Is the TMS Team\\napproachable\", \"Is the TMS Team\\napproachable\", \r\n    \"Is the TMS Team\\napproachable\", \"Is the TMS Team\\napproachable\", \r\n    \"Is the TMS Team\\napproachable\", \"They give you\\nthe chance to\\nlisten to your\\ncall\", \r\n    \"They give you\\nthe chance to\\nlisten to your\\ncall\", \"They give you\\nthe chance to\\nlisten to your\\ncall\", \r\n    \"They give you\\nthe chance to\\nlisten to your\\ncall\", \"They give you\\nthe chance to\\nlisten to your\\ncall\", \r\n    \"They fairly\\nevaluate your\\ncalls\", \"They fairly\\nevaluate your\\ncalls\", \r\n    \"They fairly\\nevaluate your\\ncalls\", \"They fairly\\nevaluate your\\ncalls\", \r\n    \"They fairly\\nevaluate your\\ncalls\", \"They explain\\nin detail the\\nresult of your\\ncall\", \r\n    \"They explain\\nin detail the\\nresult of your\\ncall\", \"They explain\\nin detail the\\nresult of your\\ncall\", \r\n    \"They explain\\nin detail the\\nresult of your\\ncall\", \"They explain\\nin detail the\\nresult of your\\ncall\", \r\n    \"They are\\nknowledgeable\\nabout H2H\", \"They are\\nknowledgeable\\nabout H2H\", \r\n    \"They are\\nknowledgeable\\nabout H2H\", \"They are\\nknowledgeable\\nabout H2H\", \r\n    \"They are\\nknowledgeable\\nabout H2H\", \"They reinforce\\nthe 3As\\napproach and\\nimportance\", \r\n    \"They reinforce\\nthe 3As\\napproach and\\nimportance\", \"They reinforce\\nthe 3As\\napproach and\\nimportance\", \r\n    \"They reinforce\\nthe 3As\\napproach and\\nimportance\", \"They reinforce\\nthe 3As\\napproach and\\nimportance\", \r\n    \"They give\\neffective\\ncoaching\\nto help you\\nimprove your\\nNS results\\nincluding H2H\\nand 3As\", \r\n    \"They give\\neffective\\ncoaching\\nto help you\\nimprove your\\nNS results\\nincluding H2H\\nand 3As\", \r\n    \"They give\\neffective\\ncoaching\\nto help you\\nimprove your\\nNS results\\nincluding H2H\\nand 3As\", \r\n    \"They give\\neffective\\ncoaching\\nto help you\\nimprove your\\nNS results\\nincluding H2H\\nand 3As\", \r\n    \"They give\\neffective\\ncoaching\\nto help you\\nimprove your\\nNS results\\nincluding H2H\\nand 3As\", \r\n    \"What is\\nthe overall\\nsatisfaction\\nregarding the\\nTMS Team\", \r\n    \"What is\\nthe overall\\nsatisfaction\\nregarding the\\nTMS Team\", \r\n    \"What is\\nthe overall\\nsatisfaction\\nregarding the\\nTMS Team\", \r\n    \"What is\\nthe overall\\nsatisfaction\\nregarding the\\nTMS Team\", \r\n    \"What is\\nthe overall\\nsatisfaction\\nregarding the\\nTMS Team\", \r\n    \"Is the TMS Team\\napproachable\", \"Is the TMS Team\\napproachable\", \r\n    \"Is the TMS Team\\napproachable\", \"Is the TMS Team\\napproachable\", \r\n    \"Is the TMS Team\\napproachable\", \"They give you\\nthe chance to\\nlisten to your\\ncall\", \r\n    \"They give you\\nthe chance to\\nlisten to your\\ncall\", \"They give you\\nthe chance to\\nlisten to your\\ncall\", \r\n    \"They give you\\nthe chance to\\nlisten to your\\ncall\", \"They give you\\nthe chance to\\nlisten to your\\ncall\", \r\n    \"They fairly\\nevaluate your\\ncalls\", \"They fairly\\nevaluate your\\ncalls\", \r\n    \"They fairly\\nevaluate your\\ncalls\", \"They fairly\\nevaluate your\\ncalls\", \r\n    \"They fairly\\nevaluate your\\ncalls\", \"They explain\\nin detail the\\nresult of your\\ncall\", \r\n    \"They explain\\nin detail the\\nresult of your\\ncall\", \"They explain\\nin detail the\\nresult of your\\ncall\", \r\n    \"They explain\\nin detail the\\nresult of your\\ncall\", \"They explain\\nin detail the\\nresult of your\\ncall\", \r\n    \"They are\\nknowledgeable\\nabout H2H\", \"They are\\nknowledgeable\\nabout H2H\", \r\n    \"They are\\nknowledgeable\\nabout H2H\", \"They are\\nknowledgeable\\nabout H2H\", \r\n    \"They are\\nknowledgeable\\nabout H2H\", \"They reinforce\\nthe 3As\\napproach and\\nimportance\", \r\n    \"They reinforce\\nthe 3As\\napproach and\\nimportance\", \"They reinforce\\nthe 3As\\napproach and\\nimportance\", \r\n    \"They reinforce\\nthe 3As\\napproach and\\nimportance\", \"They reinforce\\nthe 3As\\napproach and\\nimportance\", \r\n    \"They give\\neffective\\ncoaching\\nto help you\\nimprove your\\nNS results\\nincluding H2H\\nand 3As\", \r\n    \"They give\\neffective\\ncoaching\\nto help you\\nimprove your\\nNS results\\nincluding H2H\\nand 3As\", \r\n    \"They give\\neffective\\ncoaching\\nto help you\\nimprove your\\nNS results\\nincluding H2H\\nand 3As\", \r\n    \"They give\\neffective\\ncoaching\\nto help you\\nimprove your\\nNS results\\nincluding H2H\\nand 3As\", \r\n    \"They give\\neffective\\ncoaching\\nto help you\\nimprove your\\nNS results\\nincluding H2H\\nand 3As\", \r\n    \"What is\\nthe overall\\nsatisfaction\\nregarding the\\nTMS Team\", \r\n    \"What is\\nthe overall\\nsatisfaction\\nregarding the\\nTMS Team\", \r\n    \"What is\\nthe overall\\nsatisfaction\\nregarding the\\nTMS Team\", \r\n    \"What is\\nthe overall\\nsatisfaction\\nregarding the\\nTMS Team\", \r\n    \"What is\\nthe overall\\nsatisfaction\\nregarding the\\nTMS Team\"\r\n    )), .Names = c(\"value\", \"site\", \"variable\", \"score\", \"Position\", \r\n\"variable2\"), row.names = c(NA, 80L), vars = list(variable), labels = structure(list(\r\n    variable = structure(1:8, .Label = c(\"Is.the.TMS.Team.approachable.\", \r\n    \"They.give.you.the.chance.to.listen.to.your.call.\", \"They.fairly.evaluate.your.calls.\", \r\n    \"They.explain.in.detail.the.result.of.your.call.\", \"They.are.knowledgeable.about.H2H.\", \r\n    \"They.reinforce.the.3As.approach.and.importance.\", \"They.give.effective.coaching.to.help.you.improve.your.NS.results..including.H2H.and.3As.\", \r\n    \"What.is.the.overall.satisfaction.regarding.the.TMS.Team..\"\r\n    ), class = \"factor\")), class = \"data.frame\", row.names = c(NA, \r\n-8L), .Names = \"variable\", vars = list(variable)), indices = list(\r\n    0:4, 5:9, 10:14, 15:19, 20:24, 25:29, 30:34, 35:39), class = c(\"grouped_df\", \r\n\"tbl_df\", \"tbl\", \"data.frame\"))\r\n```\r\nThe code to reproduce the chart is:\r\n```\r\nggplot(table.merged,aes(variable2,score,fill=value))+\r\n  geom_bar(stat=\"identity\",alpha=0.6,colour=\"grey60\")+\r\n  geom_text(aes(label=round(score,2),y=table.merged$Position),colour=\"white\")+\r\n  facet_wrap(~site)+\r\n  scale_fill_manual(values=c(\"darkred\",\"red\",\"orange\",\"green\",\"darkgreen\"))+\r\n  labs(title=\"General satisfaction with TMS\", y=\"Percentage\",x=\"\")+\r\n  theme(plot.title=element_text(vjust=1),\r\n        legend.position=\"top\",\r\n        legend.title=element_blank()) \r\n```\r\nThank you"},"comment":{"url":"https://api.github.com/repos/hadley/ggplot2/issues/comments/136033445","html_url":"https://github.com/hadley/ggplot2/issues/1301#issuecomment-136033445","issue_url":"https://api.github.com/repos/hadley/ggplot2/issues/1301","id":136033445,"user":{"login":"hadley","id":4196,"avatar_url":"https://avatars.githubusercontent.com/u/4196?v=3","gravatar_id":"","url":"https://api.github.com/users/hadley","html_url":"https://github.com/hadley","followers_url":"https://api.github.com/users/hadley/followers","following_url":"https://api.github.com/users/hadley/following{/other_user}","gists_url":"https://api.github.com/users/hadley/gists{/gist_id}","starred_url":"https://api.github.com/users/hadley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hadley/subscriptions","organizations_url":"https://api.github.com/users/hadley/orgs","repos_url":"https://api.github.com/users/hadley/repos","events_url":"https://api.github.com/users/hadley/events{/privacy}","received_events_url":"https://api.github.com/users/hadley/received_events","type":"User","site_admin":false},"created_at":"2015-08-29T19:45:44Z","updated_at":"2015-08-29T19:45:44Z","body":"If you prepare a _minimal_ example I can take a look but there's too much extraneous detail in your current code. "}}