您的第一个 beeswarm 图
下面的代码为性别与超速数据绘制了一个简单的 beeswarm 图,与上一课中看到的类似。
您会注意到,因为点的堆叠导致两个性别的分布有重叠,所以图形效果不太理想。
请修正该图:将 cex 参数设为 0.5 来减小点的大小,并为点设置不透明度,使图面不那么生硬,同时更突出单个观测点。
另外,在这些点上方叠加一层透明的箱线图,以提供基本的汇总统计信息。
本练习是课程的一部分
R 中的可视化最佳实践
练习说明
- 在 beeswarm 图层中设置
cex = 0.5,以减小点的大小。 - 将点的
alpha设为 0.8。 - 在 beeswarm 上方添加一层透明的箱线图。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Load library for making beeswarm plots
library(ggbeeswarm)
md_speeding %>%
filter(vehicle_color == 'RED') %>%
ggplot(aes(x = gender, y = speed)) +
# change point size to 0.5 and alpha to 0.8
geom_beeswarm(___) +
# add a transparent boxplot on top of points
___