R Scatterplot/bubble 图表,点大小基于观察数

R Scatterplot/bubble chart with dot size based on observation number

我知道这个问题已经有点回答了here, here and here

在所有这些示例中,dot/bubble 大小基于第三个因素,例如 size

但是,在我的数据中,我只有 2 个变量,xvalyval

library("ggplot2")
xval <- c("0","0.5","0.25","0","0")
yval <- c("1","0.5","0.25","0.25","1")
df.test <- data.frame(xval,yval)
df.test
p <- ggplot(df.test, aes(x = xval, y = yval)) + geom_point()
p

这里是df.test

  xval yval
1    0    1
2  0.5  0.5
3 0.25 0.25
4    0 0.25
5    0    1

这里是p

我想要的是 每个 dot/bubble 大小取决于该坐标的观测值的出现次数。 例如,(0,1) 将是其他点的两倍大。我想避免将第 3 列添加到我的数据框中,并让 R 自动执行它。

我不知道这是否可以在不必过多处理数据的情况下完成...任何见解将不胜感激:)

使用geom_count()

xval <- c("0","0.5","0.25","0","0")
yval <- c("1","0.5","0.25","0.25","1")
df.test <- data.frame(xval,yval)
df.test

ggplot(df.test, aes(x = xval, y = yval)) + geom_count()