r - 用线将观测值连接到一个公共点(即 (0,0))
问题描述
我想使用ggplot2 将来自我的 df 的观察结果与一个公共点连接起来,即中心点 (0,0) 。
x y
1 5 4
2 -4 -2
3 -1 5
4 2 -8
现在,我想要将四个观测值与 (0,0) 处的中心点连接起来,如下所示(不是用 R 制作的):
这可能使用ggplot2吗?
解决方案
我找到了一个解决方案:
ggplot(df) + geom_point(aes(x,y)) + geom_segment(aes(xend=0, yend=0))
根据@roland对问题的评论进行回答。