ggplot2 数据可视化进阶
Rick Scavetta
Founder, Scavetta Academy
| 过度重叠的原因 | 解决方案 | |
|---|---|---|
| 1. | 数据量大 | 透明度混合、空心圆、点大小 |
| 2. | 单轴上值对齐 | 同上,另可改变位置 |
| 3. | 低精度数据 | 位置:抖动 |
| 4. | 整数数据 | 位置:抖动 |
| 过度重叠的原因 | 解决方案 | 此处… | |
|---|---|---|---|
| 1. | 数据量大 | 透明度混合、空心圆、点大小 | |
| 2. | 单轴上值对齐 | 同上,另可改变位置 | |
| 3. | 低精度数据 | 位置:抖动 | geom_count() |
| 4. | 整数数据 | 位置:抖动 | geom_count() |
p <- ggplot(iris, aes(Sepal.Length,
Sepal.Width))
p + geom_point()

p + geom_jitter(alpha = 0.5,
width = 0.1,
height = 0.1)

p +
geom_count()

| geom_ | stat_ |
|---|---|
geom_count() |
stat_sum() |
p +
stat_sum()

ggplot(iris, aes(Sepal.Length,
Sepal.Width,
color = Species)) +
geom_count(alpha = 0.4)

ggplot(iris, aes(Sepal.Length,
Sepal.Width,
color = Species)) +
geom_count(alpha = 0.4)
library(AER)
data(Journals)
p <- ggplot(Journals,
aes(log(price/citations),
log(subs))) +
geom_point(alpha = 0.5) +
labs(...)
p

p +
geom_quantile(quantiles =
c(0.05, 0.50, 0.95))

| geom_ | stat_ |
|---|---|
geom_count() |
stat_sum() |
geom_quantile() |
stat_quantile() |
ggplot2 数据可视化进阶