如何向 ggplot 添加另一层/新系列?
在 ggplot 中,我可以将一个系列添加到绘图中:
ggplot(diamonds, aes(x = carat, y = price)) + geom_point()
如何简单地添加另一个系列,例如绘制红宝石与钻石的成本。假设红宝石也在钻石数据集中。我尝试在上面放置另一层红宝石数据,但它只绘制红宝石而不是钻石/克拉。
ggplot(diamonds, aes(x = carat, y = price)) + geom_point() + aes(x = rubies, y = price)
我可以看到,通过首先将所有数据融合在一起,准备绘制它,这是可能的,所以也许我应该走这条路。然而,仅仅在这样的情节中添加另一个系列似乎应该不会太难,但我不知道该怎么做。
In ggplot I can add a series to a plot with:
ggplot(diamonds, aes(x = carat, y = price)) + geom_point()
How do I simply add another series, e.g. plotting the cost of rubies against diamonds. Assuming rubies was also in the diamonds dataset. I have tried to lay over the top another layer with the rubies data, but it just plots the rubies and not the diamonds/carat.
ggplot(diamonds, aes(x = carat, y = price)) + geom_point() + aes(x = rubies, y = price)
I can see that this would be possible by melding all the data together first, ready to plot it, so maybe I should go down that route. However, just adding another series to a plot like this seems like it should not be too hard, but I can't figure out how to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)