【报错】Error: stat_bin() must not be used with a y aesthetic.
在进行ggplot绘图的过程中,出现了“Error: stat_bin() must not be used with a y aesthetic.”的报错。
代码具体如下:
> ggplot(aes(x = gender, y = age),
+ data = subset(pf, !is.na(gender))) + geom_histogram()
Error: stat_bin() must not be used with a y aesthetic.
> ggplot(aes(x = age, y = friend_count),
+ data = subset(pf, !is.na(gender))) + geom_histogram()+
+ facet_wrap(~gender,ncol = 1)
Error: stat_bin() must not be used with a y aesthetic.
stat_bin表明统计变换是计数,计数会被投射到y轴,与y=1冲突了, 所以才出现stat_bin() must not be used with a y aesthetic.
这里主要是因为直方图是单因素变量的可视化方法,aes包裹中不能添加y轴。正确的代码可更换为一下:
ggplot(aes(x = friend_count),data = subset(pf, !is.na(gender))) + geom_histogram()ggplot(aes(x = friend_count),data = subset(pf, !is.na(gender))) + geom_histogram()+facet_wrap(~gender,ncol = 1)
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
