I have the following data frame:
> DF
Year Metric MWh
2003 Demand 498343
2004 Demand 1250904
2005 Demand 1665176
2006 Demand 2317643
2007 Demand 2455311
2008 Demand 3557987
2009 Demand 4268125
2010 Demand 5403704
2011 Demand 6596158
2012 Demand 7814387
2013 Demand 9008863
2014 Demand 10291085
2015 Demand 11796549
2003 Actual 159677
2004 Actual 192748
2005 Actual 248844
2006 Actual 372661
2007 Actual 705656
2008 Actual 838721
2009 Actual 1188242
2010 Actual 1708979
2011 Actual 0
2012 Actual 0
2013 Actual 0
2014 Actual 0
2015 Actual 0
2003 High 0
2004 High 0
2005 High 0
2006 High 0
2007 High 0
2008 High 0
2009 High 0
2010 High 0
2011 High 3631730
2012 High 5729024
2013 High 6741785
2014 High 9342798
2015 High 11094798
2003 Low 0
2004 Low 0
2005 Low 0
2006 Low 0
2007 Low 0
2008 Low 0
2009 Low 0
2010 Low 0
2011 Low 1637220
2012 Low 1850615
2013 Low 2064011
2014 Low 2277406
2015 Low 2490801
I want to create a very simple stacked bar chart with:
-- x-axis: Year
-- y-axis: MWh
-- 1 stack with Demand, High, Low, and Actual ('Metric'), in that order, stacked OVER one another (as opposed to on-top). So far, I've only managed to figure out how to do it with the values stacked ON TOP of each other:
DF$'Metric <- factor(DF$'Metric',levels=c("Demand","High","Low","Actual"))
qplot(x=Year,data=DF,geom="bar",weight=MWh,fill=Metric)
#OR
ggplot(DF,aes(x=factor(Year),y=MWh,fill=factor(Metric))) + geom_bar(position="stack")
Essentially, what I'm looking for is a single bar per year where the "Demand" value is the highest, and the lower values (in the order above) are stacked over. I believe I have to use a position="fill"
somewhere, but I'm not sure where to put it. Basically, what I am trying to show is that Demand will be steadily rising, while Supply (Actual vs. projected Low growth vs. projected High growth) has been unable to meet it in a very simple, compact graphic. If this is not possible, perhaps it would be better to simply group them side-by-side?
Any help is much appreciated!! Thanks!!
position="identity"
. – Aniko