R语言 ggplot2:只左右抖动jitter散点图
R语言 ggplot2:只左右抖动jitter散点图
在使用R语言的ggplot2包绘制散点图时,geom_jitter()函数可以用来避免数据点重叠,但默认情况下,它会在x轴和y轴上随机分配位置,导致上下抖动。如果想要只左右抖动,可以将height参数设置为0,即:
ggplot(tips,
aes(1, size)) +
geom_boxplot(width = .4, fill = '#f8766d') +
geom_point() +
geom_jitter(width = .1, height = 0) +
scale_x_continuous(limits = c(0.5, 1.5)) +
labs(title = 'Boxplot of size($)', x = NULL, y = 'size') +
theme_bw()
这样就只会在x轴上进行左右抖动了。
原文地址: https://www.cveoy.top/t/topic/nbk3 著作权归作者所有。请勿转载和采集!