如果我有两组坐标,其中x和y代表圆心,大小代表圆半径,那么如何在ggplot2中用它们绘制圆呢?我看到了this问题,但这是关于绘制单个圆的问题,我找不到使用散点图复制它的方法。
示例数据:
x y sizes
0.95285914 0.06596914 0.8868900
-1.59822942 0.71052036 2.3087498
0.39216559 0.58428603 0.1921204
0.16559318 -0.99303562 1.1586288
-0.43047728 -0.96649463 0.5360174
-0.73746484 -0.21143717 0.5260277
0.58779207 0.08073626 0.5070558
0.74936811 0.54462816 0.2047399
-0.01587290 -0.14835109 0.1324782
-0.06573365 0.33317857 0.3989122
答案 0 :(得分:4)
library(ggplot2)
library(ggforce)
dat = read.table(text=" x y sizes
0.95285914 0.06596914 0.8868900
-1.59822942 0.71052036 2.3087498
0.39216559 0.58428603 0.1921204
0.16559318 -0.99303562 1.1586288
-0.43047728 -0.96649463 0.5360174
-0.73746484 -0.21143717 0.5260277
0.58779207 0.08073626 0.5070558
0.74936811 0.54462816 0.2047399
-0.01587290 -0.14835109 0.1324782
-0.06573365 0.33317857 0.3989122", header=TRUE)
ggplot(dat, aes(x0=x, y0=y, r=sizes)) +
geom_circle() + coord_equal() + theme_classic()