我正在与 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
我给分面变量上了颜色,试图帮助说明发生了什么。该图的每个方面应该只有一种颜色,而不是您在此处看到的颜色。有谁知道发生了什么事吗?
此错误是由于您正在使用$
和数据框名称来引用您的变量aes()
. Using ggplot()
你应该只使用变量名称aes()
因为数据框已被命名data=
.
plot = ggplot(data = item.household.descr.count,
mapping = aes(x=freq, y = descr, color = age.cat)) + geom_point()
plot = plot + facet_wrap(~ age.cat, ncol = 2)
plot
这是使用钻石数据集的示例。
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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)