R:如何创建具有不同颜色的重复点的基本 x,y 图(2 个变量)(~heatmap)

R: How to create a basic x,y plot (2 vars) with repeated points having a different color (~heatmap)

这个情节: 情节(数据$等级,数据$缺失) 生成我需要的图,除了我需要能够识别重复的值。

缺勤范围从 0 到 19。成绩范围从 0 到 10(整数)。 共有320名学生。

例如,缺席为 0 的 7 分有 84 次重复。

我想要一个按比例缩放的热图,其中一个点的颜色从浅蓝色(1 个数据点)开始,按比例放大到深蓝色(>70),有 7 个步骤。 (大约。)不同颜色的热图点也可以。

可能有一个构建热图的特定函数,但您可以计算 df 中唯一行的数量(使用 dplyr)并将该计数用作 alpha(透明度) ggplot2 上的参数:

library(ggplot2)
library(dplyr)

df = data.frame( # Creating some dummy data
  Grades = sample(0:10, 10000, TRUE),
  Abscences = sample(0:19, 10000, TRUE)) 

df = df %>% group_by_all() %>% summarise(COUNT = n())

ggplot(df, aes(y=Grades, x=Abscences, alpha=COUNT)) +
  geom_point(color="darkblue", size=5, shape="square")

输出: