I am using ggplot
to draw a bar chart. How can I change the order of the groups in the bars? In the following example, I want to have type=1984 as the first stack of the bars, then type=1985 on top of 1984 and so on.
series <- data.frame(
time = c(rep(1, 4),rep(2, 4), rep(3, 4), rep(4, 4)),
type = c(1984:1987),
value = rpois(16, 10)
)
ggplot(series, aes(time, value, group = type)) +
geom_col(aes(fill= type))
Changing the order using series<- series[order(series$type, decreasing=T),]
only changes the order in the legend not in the plot.
desc()
is coming from. – Conservation