首页 > 解决方案 > 用线将观测值连接到一个公共点(即 (0,0))

问题描述

我想使用ggplot2 将来自我的 df 的观察结果与一个公共点连接起来,即中心点 (0,0) 。

x y
1 5 4
2 -4 -2
3 -1 5
4 2  -8

使用 geom_point(),我得到以下信息。 使用 geom_point() 绘图

现在,我想要将四个观测值与 (0,0) 处的中心点连接起来,如下所示(不是用 R 制作的):

我想拥有的插图

这可能使用ggplot2吗?

标签: rggplot2

解决方案


我找到了一个解决方案:

ggplot(df) + geom_point(aes(x,y)) + geom_segment(aes(xend=0, yend=0))

根据@roland对问题的评论进行回答。


推荐阅读