r面_包裹未与几何点正确分组

r面_包裹未与几何点正确分组,r,ggplot2,facet-wrap,R,Ggplot2,Facet Wrap,我正在努力使用R中的facet_wrap。它应该很简单,但是facet变量没有被拾取?以下是我正在运行的: plot = ggplot(data = item.household.descr.count, mapping = aes(x=item.household.descr.count$freq, y = item.household.descr.count$descr, color = item.household.descr.count$age.cat)) + geom_point()

我正在努力使用R中的facet_wrap。它应该很简单,但是facet变量没有被拾取?以下是我正在运行的:

plot = ggplot(data = item.household.descr.count, mapping = aes(x=item.household.descr.count$freq, y = item.household.descr.count$descr, color = item.household.descr.count$age.cat)) + geom_point() 
plot = plot + facet_wrap(~ age.cat, ncol = 2)
plot

我给faceting变量上色,试图帮助说明发生了什么。绘图的每个方面应该只有一种颜色,而不是您在这里看到的颜色。有人知道发生了什么吗?

此错误是由于您正在使用$和数据帧名称引用aes中的变量。使用ggplot时,应仅在aes中使用变量名称,因为数据帧已在data=中命名

下面是一个使用diamonds数据集的示例

diamonds2<-diamonds[sample(nrow(diamonds),1000),]

ggplot(diamonds2,aes(diamonds2$carat,diamonds2$price,color=diamonds2$color))+geom_point()+
          facet_wrap(~color)

物品中有什么。家居。描述。计数谢谢!一段时间以来,我一直在努力解决这个问题。
diamonds2<-diamonds[sample(nrow(diamonds),1000),]

ggplot(diamonds2,aes(diamonds2$carat,diamonds2$price,color=diamonds2$color))+geom_point()+
          facet_wrap(~color)
ggplot(diamonds2,aes(carat,price,color=color))+geom_point()+
  facet_wrap(~color)