I am trying to build a stacked bar chart based on percent exceedance. The plot orders the data by the size of the value, not the order of the percent exceedance. Here is the data and the ggplot code used:
Qs_melt$Quartiles <- c(1,0.75,0.5,0.25,0,1,0.75,0.5,0.25,0,1,0.75,0.5,0.25,0)
Qs_melt$Labels <- c("Min", "75%E", "50%E","25%E","Max","Min", "75%E", "50%E","25%E","Max","Min", "75%E", "50%E","25%E","Max")
Qs_melt$variable <- c("May Remaining", "May Remaining", "May Remaining", "May Remaining", "May Remaining", "June_diff", "June_diff", "June_diff","June_diff","June_diff", "July_diff","July_diff","July_diff","July_diff","July_diff")
Qs$value <- c(16.2,10,5,4,0.2,28,16,20,11,13,14,16)
ggplot(Qs_melt) +
aes(x = variable, y = value, fill = Labels) +
geom_bar(stat = "identity", position = "stack") +
scale_fill_manual("Legend", values = c("Max" = 'red', '25%E' = 'orange', '50%E' = 'green', '75%E' = 'darkblue', 'Min' = 'lightblue'))
Is it possible to order the plot by the Qs_melt$Quartiles order? The max category needs to be on the top of the bar chart. I need the legend to use the values from the Qs_melt$Labels column though.
Order the factor of fill Labels Like this?
ggplot(Qs_melt) +
aes(x = variable, y = value, fill = factor(Labels, level=c("Max", "75%E", "50%E","25%E","Min"))) +
geom_bar(stat = "identity", position = "stack") +
scale_fill_manual("Legend", values = c("Max" = 'red', '25%E' = 'orange', '50%E' = 'green', '75%E' = 'darkblue', 'Min' = 'lightblue'))
i added some data, because your sampledata had some missing values