PDF 126 / 520 The size of each circle in the plot displays how many observations occurred at each combination
English · PDF 126
Original PDF page 126
中文 · PDF 126

图中每个圆圈的大小表示在每个数值组合上出现了多少次观测。协变会表现为特定 x 值与特定 y 值之间的强相关性。

另一种方法是使用 dplyr 计算计数:

diamonds %>% count(color, cut) #> Source: local data frame [35 x 3] #> Groups: color [?] #> #> color cut n #> #> 1 D 一般 163 #> 2 D 好 662 #> 3 D 很好 1513 #> 4 D 优质 1603 #> 5 D 理想 2834 #> 6 E 一般 224 #> # ... 还有 29 行

然后用 geom_tile() 和 fill 美学进行可视化:

diamonds %>% count(color, cut) %>% ggplot(mapping = aes(x = color, y = cut)) + geom_tile(mapping = aes(fill = n))