【发布时间】:2020-08-19 02:47:32
【问题描述】:
我有两个数据框,我想对它们进行比较。情节和数据框看起来像这样
df2019 <- data.frame(Institute = c("A","B","C"),Women = c(65,50,70),Men = c(35,50,30))
df2016 <- data.frame(Institute = c("A","B","C"),Women = c(70,45,50),Men = c(30,55,50))
df2019_melted <- melt(df2019)
ggplot(data = df2019_melted, aes(x = Institute, y = value, fill = variable))+
geom_bar(stat = "identity", position = "dodge")+
labs(fill = "Gender")+
xlab("Institute")+
ylab("Percent")+
scale_fill_discrete(labels = c("Women","Men"))+
ggtitle("Overall Gender Composition 2019")
但我希望情节以褪色条形显示 2016 年,但分组方式与 2019 年相同,因此每个研究所 4 个条形。
由于我的所有数据帧的列名都相同,因此我不能使用 rbind() 或类似方法,因为它无法区分组合时的数据帧。
【问题讨论】: