I am attempting to make a faceted barchart with each facet representing a sector of employment with three time points for each display.
Here's my code and sample data
Year <- c("2002", "2010", "2012", "2002", "2010", "2012", "2002", "2010", "2012")
Year <- ordered(Year, levels = c("2002", "2010", "2012"))
Sector <- c("Production", "Processing", "Distribution", "Production", "Processing", "Distribution",
"Production", "Processing", "Distribution")
Sector <- ordered(Sector, levels = c("Production", "Processing", "Distribution"))
Avg.Emp <- c(363, 4458, 2962, 225, 4767, 3552, 148, 5137, 3996)
df <- data.frame(Year, Sector, Avg.Emp)
When checking data types everything checks out. My factors are ordered properly and my employment figures line up with their proper factors. When I attempt to use ggplot, though, I run into an issue. The ggplot code:
library(ggplot2)
library(scales)
sampleplot <- ggplot(df, aes(x=Year, y=Avg.Emp)) + geom_bar(stat = "identity") +
facet_wrap(~Sector) + ylim(0,5200)
My resulting plot is only showing a single value for each year in the facets. Where am I making my mistake? (I apologize for the lack of an image, I don't have enough reputation for it) Is there anyway I can get my values for each year to show in the proper facets?
EDIT I realize I only had one sector per year given the way I made my dataframe. The updated syntax is here and fixed the issue
Year <- c("2002", "2002", "2002", "2010", "2010","2010","2012","2012","2012")
Year <- ordered(Year, levels = c("2002", "2010", "2012"))
Sector <- c("Production", "Processing", "Distribution", "Production", "Processing", "Distribution",
"Production", "Processing", "Distribution")
Sector <- ordered(Sector, levels = c("Production", "Processing", "Distribution"))
Avg.Emp <- c(363, 4458, 2962, 225, 4767, 3552, 148, 5137, 3996)
df <- data.frame(Year, Sector, Avg.Emp)