I have edited the data below so that it's dummy data. The column for Source has proprietary names.
I have data that look like this and I would like to rearrange my stacked chart by rank and NOT source but would like my legend to reflect Source.
TotalBySource <- read.table(header=TRUE, stringsAsFactors=FALSE,
text="FY Source Rank TotalExpense TotalforFY Percent
2006 Option1 1 46753094.2 121493809.7 0.384818735
2006 Option7 7 7113652.3 121493809.7 0.058551562
2006 Option6 6 34461918.9 121493809.7 0.283651644
2006 Option8 8 10586263.1 121493809.7 0.087134177
2006 Option5 5 1777846.8 121493809.7 0.014633229
2006 Option4 4 17886868.4 121493809.7 0.147224525
2006 Option3 3 2118019.3 121493809.7 0.017433146
2006 Option2 2 796146.7 121493809.7 0.006552982
2007 Option7 7 6833612 118232170.7 0.057798245
2007 Option5 5 1676225.2 118232170.7 0.014177404
2007 Option6 6 35245142.1 118232170.7 0.298101117
2007 Option3 3 2283154.9 118232170.7 0.019310775
2007 Option4 4 17948447.3 118232170.7 0.151806798
2007 Option8 8 10279117 118232170.7 0.086940102
2007 Option1 1 43397313.8 118232170.7 0.367051654
2007 Option2 2 569158.4 118232170.7 0.004813905
2008 Option1 1 43962329.7 115013461.7 0.382236384
2008 Option7 7 6745206.4 115013461.7 0.058647104
2008 Option6 6 34288244.4 115013461.7 0.298123749
2008 Option8 8 10304301.5 115013461.7 0.089592134
2008 Option5 5 1551682.9 115013461.7 0.013491316
2008 Option4 4 15180864 115013461.7 0.131992062
2008 Option3 3 2398345.7 115013461.7 0.020852739
2008 Option2 2 582487.1 115013461.7 0.005064512")
I constructed this code:
library(ggplot2)
p4 <- ggplot() +
geom_bar(aes(y = Percent, x = FY, fill = Source), data = TotalBySource, stat="identity")
and got a lovely stacked bar graph
but would really want the stacks and the legend to be sorted by rank and the legend to read the respective Source. Can I get some assistance?