上下抖动是因为在默认情况下,geom_jitter()函数会在x轴上随机分配位置,而y轴上则会根据数据值进行抖动。如果想要只左右抖动,可以将y参数设置为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轴上进行左右抖动了。

R语言ggplottips aes1 size + geom_boxplotwidth = 4 fill = #f8766d + geom_point+ geom_jitterwidth = 1+ scale_x_continuouslimits = c05 15+ labstitle = Boxplot of size$ x = NULL y = size+ theme

原文地址: https://www.cveoy.top/t/topic/bH30 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录