我正在尝试制作一个刻面的条形图,每个方面代表一个就业部门,每个显示器有三个时间点。
这是我的代码和示例数据
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)
检查数据类型时,所有内容都会检出。我的因素是正确的,我的就业数据与他们的正确因素排列在一起。但是当我尝试使用ggplot时,我遇到了一个问题。 ggplot代码:
library(ggplot2)
library(scales)
sampleplot <- ggplot(df, aes(x=Year, y=Avg.Emp)) + geom_bar(stat = "identity") +
facet_wrap(~Sector) + ylim(0,5200)
我的结果图只显示了每个方面的单个值。我在哪里弄错了? (我为缺少图像而道歉,我没有足够的声誉) 无论如何,我有可能每年都能得到我的价值观,以便在适当的方面表现出来吗?
修改 根据我制作数据帧的方式,我意识到每年只有一个扇区。 更新的语法在这里并修复了问题
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&lt; - data.frame(Year,Sector,Avg.Emp)