Hello Everyone,
I am new to R and ggplot2, after a lot of struggle, watching videos and going through various open source sites I have created bar chart for my data.
My data has four columns i.e. Items, Quantity_2001, Quantity_2011 and Change. There are 11 different items with no missing vales. I want to create a side-by-side bar chart where each 'Item' will have three bars: one bar for 2001, one bar for 2011 and one bar for Change. I have managed to create one using the following set of commands:
library(ggplot2)
library(tidyverse)
library(dplyr)
df <- gather(Data, variable, value, -Item)
ggplot(df, aes(Item, value, fill = variable)) +
geom_bar(stat = "identity", position = "dodge", width=0.7)+
labs(y = "Sales") +
theme(axis.text.x = element_text(angle = 90)) +
scale_y_continuous(limits=c(-17, 45), breaks=seq(-17, 45, 10))+
scale_fill_discrete(name="Legend", labels=c("Quantity 2001", "Quantity 2011", "Change"))
So there are three bars for each item, for example 'Item1' has three bars one each for 2001, 2011 and change and so on for all 11 items. However, with the above command, the bars for each item in the chart appear first for 2011, then for 2001 and then change. I want bar for 2001 to appear first, then 2011 and then change. Please let me know if there is a way I can manually reorder the bars.
Thanks,
Raj