Stacked Area Graphs

I am working on a stacked area graph and need to reverse the order of stacks in the graph. Its a large dataframe, but it only has 3 variables once gathered into tidy format - Month , area , and volume . I wasn't able to create reprex with the data.

The code for the graph is as follows:

ggplot(neb6) +
  geom_area(aes(x=Month, y= volume/1000000, fill=area), show.legend = NA) +
  labs(y="MMbbl/d", x="Year", title="Condensate", 
       caption="Source: NEB") +
  theme_bw() 

The graph fills the area on the y-axis using the smallest fill, or stacked area, up to the largest. A picture of the graph is attached. Is it possible to change the order in the stacked areas so they dont drop to zero?

The ordering is based on the factor ordering of area. You can either change that, or use position = position_stack(reverse = TRUE) in geom_area.

2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.