我试图建立一个带有气泡的xy图,这个尺寸取决于数据点的频率/密度和这个气泡的xy坐标(或者这个气泡的xy坐标范围)。
# example of data
d <- data.frame(x=c(1,1,1,1,2,2), y=c(1,1,2,3,2,3))
# chart form ggplot2 book, that has xy-coordinates and size,
# but size is a duplicate of y-coordinate
ggplot(d, aes(x)) +
stat_bin(aes(size = ..density..), binwidth = 0.1, geom = "point", position="identity")
# most close result I got with density.
# But this density2d:
# 1) put geoms where there is no data points and
# 2) not ONE bubble for bin
ggplot(data=d, aes(x=x, y=y)) +
stat_density2d(geom="point", aes(size = ..density.., alpha=..density..), contour=F)
我见过先前数据转换的解决方案,即创建data.frame,其中所有可能的xy-coordinates对列在2列中,频率计数在额外列中。 但这不美观,不灵活,在我的案例中可能需要很多空间。