【发布时间】:2023-04-06 18:04:01
【问题描述】:
我有一个使用以下代码生成的箱线图:
b.males <- c(6, 7, 8, 8, 8, 9, 10, 10, 11, 11, 12, 12, 12, 12, 13, 14, 15)
b.females <- c(14, 13, 12, 12, 11, 10, 10, 9, 9, 9, 9, 9, 8, 8, 8, 7, 7, 7, 7)
b.total<-c(b.males,b.females)
b.m<-data.frame(b.males)
b.f<-data.frame(b.females)
b.t<-data.frame(b.total)
myList<-list(b.m, b.f, b.t)
df<-melt(myList)
colnames(df) <- c("class","count")
plt<-ggplot(df, aes(x=class,y=count))+geom_boxplot()
plt + geom_point(aes(x = as.numeric(class) + 0, colour=class))
我想做的是,对于任何给定的 y 轴点,连续显示所有单独的点。例如,对于 b.males,我希望在 8 处看到 3 个点,中间的点正好在中心,另外两个点就在它旁边。
我尝试过:
plt + geom_point(aes(x = as.numeric(class) + 0, colour=class)) +
geom_jitter(position=position_jitter(width=.1, height=0))
但这并没有使这些点保持紧密。此外,在某些情况下,它会将多个点放在框中间的右侧或左侧,而不是按照我的意愿均匀分布。
【问题讨论】: