R 绘制两个数据集的最佳方法,这两个数据集以长格式组合在一起

R 绘制两个数据集的最佳方法,这两个数据集以长格式组合在一起,r,plot,R,Plot,我认为最好用一个例子来解释。假设我有6对男女,12个人中的每一个人都有一定的薪水,如下面的data.frame所示 xx <- data.frame (gender = c(rep("man", 6), rep("woman", 6)), couple = c(1:6, 1:6), salary = c(1:6, seq (2, 12, 2))) xx <- xx[sample (1:nrow(xx)),

我认为最好用一个例子来解释。假设我有6对男女,12个人中的每一个人都有一定的薪水,如下面的data.frame所示

xx <- data.frame (gender = c(rep("man", 6), rep("woman", 6)), 
                  couple = c(1:6, 1:6), 
                  salary = c(1:6, seq (2, 12, 2)))

xx <- xx[sample (1:nrow(xx)), ]

xx一种方法是这样做

library(ggplot2)

ggplot(xx,aes(x=couple,y=salary,fill=gender))+geom_bar(stat="identity",position="dodge")
您还可以在
aes
语句中尝试
x=factor(couple)
,该语句将标记每一对


这是一个很好的解决方案,但我需要一个散点图,因为我有数千个点