Probably a simple question, but I just cannot seem to find the answer: I would like to change the order of the stacked bars in my diagram. In the "semi-natural" group, the stacked bars shall be displayed "Forest", then "Shrubland", then "Grassland", from bottom to top. In the "cropland" group, the stacked bars shall be displayed "Mixed Cropland", "Rice-Wheat", "Sugarcane", from bottom to top. Thanks for your help!
data <- read_excel("C:/lulc_change_analysis.xlsx")
data1 <- data
data1$group <- factor(data1$group, levels = c("Semi-natural", "Water", "Cropland", "Urban"))
ggplot(data=data1, aes(x=year, y=value,fill=lulc)) + geom_bar(color = "black", stat="identity") +
facet_grid(~group) +
scale_fill_manual("legend", values = c("Forest" = "green4", "Shrubland" = "green3", "Grassland" = "chartreuse",
"Water" = "blue", "Sugarcane" = "magenta", "Rice-Wheat" = "grey",
"Mixed Cropland" = "yellow", "Urban" = "red")) +
labs(y= "Percentage of catchment area (%)") +
theme(axis.title = element_text(face="bold")) +
theme(legend.title = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), panel.background = element_blank(),
axis.line = element_blank(), axis.ticks.x = element_blank(), axis.title.x = element_blank(),
axis.text.x = element_text(size=7))