一起绘制geom_bar和geom_point? [英] Plotting geom_bar and geom_point together?
本文介绍了一起绘制geom_bar和geom_point?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
data=data.frame(x=rep(0:9, each=2))
ggplot(data, aes(x=factor(x))) + geom_bar(alpha=0.5) +
geom_point(data=data.frame(x=0:10, y=2), aes(x=factor(x), y=y), alpha=0.5)
ggplot(data, aes(x=factor(x))) + geom_bar(alpha=0.5) +
geom_point(data=data.frame(x=0:10, y=2), aes(x=factor(x), y=y), alpha=0.5) +
scale_x_discrete(limits=0:10)
此外,鉴于 x
是 integer
,因此我已经是离散的,我是否必须 factor
?错误的顺序x轴标签错误.
Also, do I have to factor
given x
is integer
so it is discrete already?
Wrong order
Wrong x axis label.
推荐答案
ggplot(data, aes(x=x)) + geom_bar(alpha=0.5) + scale_x_discrete(limits=0:10) +
geom_point(data=data.frame(x=0:10, y=2), aes(x=x, y=y), alpha=0.5)
您可以强制使用离散比例尺来获得所需的东西.奇怪的是,当您混合使用geom_point()和geom_bar()时,ggplot开始以意外的方式对事物进行排序.
You can force a discrete scale to get what you want. It is odd how when you mix geom_point() and geom_bar() ggplot starts ordering things in unexpected ways.
这篇关于一起绘制geom_bar和geom_point?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文