【发布时间】:2023-01-22 22:34:15
【问题描述】:
由于不同组之间的重叠,我在管理 geom_dotplot 函数中的多个观察时遇到了问题:
v1 <- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2)
v2 <- c(0,0,0,0,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2)
v3 <- c(13,67,89,280,40,1,23,99,32,1,75,280,270,200,196,300,320,277,23,4,1,2,5,89,45,23,11,1,3,23,100,100,100,100,100,200,100,11,6,6,123,100,100,100,100,100,12,86,11,300,75,100,110,19,299,100,100,100,100,100,100,100,100,11,100,120,110,100,100,300,300,250,100,100,100,12,100,100,75,5,10,10,10,10,10)
summary <- data.frame(v1, v2, v3)
summary$v1 <- as.factor(summary$v1)
summary$v2 <- as.factor(summary$v2)
ggplot(summary, aes(x = v1, y = v3, fill = v2)) + geom_boxplot(width = 0.5, position = position_dodge(0.75)) + geom_dotplot(binaxis = "y", stackdir = "center", binwidth = 3.25, position = position_dodge(0.75))
图片示例:https://i.stack.imgur.com/eLmee.png
我考虑过手动更改数据,目的是最多只有 5 个具有相同值的观察值(例如 v3 <- (... 100, 100, 100, 100, 100, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 130, ...))。但是,它也会影响箱线图的结果(中位数、四分位间距)。
我找不到任何选项可以在 5 个点后自动中断以不重叠。也许,有一个简单而巧妙的解决方案。感谢您的所有帮助。先感谢您!
【问题讨论】: