r - 如何使 geom_path 对应 geom_beeswarm 点
问题描述
我一直试图在一个小样本中可视化几个特征的关联。
这是一个示例数据:
set.seed(309)
dat <- data.frame(id=c(1:9, 5:9, 7:9),
count=c(sample(1:4,9, prob=c(.5,.3,.2,.1), replace = T),
c(1,1,3,2,4), c(1,2,1)),
strain=c(rep("A", 9), rep("B", 5), rep("C", 3)))
dat$feature <- (dat$id%%2==0)*1 + (dat$id%%2!=0)*0
dat$id <- as.factor(dat$id)
dat$feature <- factor(dat$feature, labels=c("X","Y"))
我这样尝试过geom_point
:
library(ggplot2)
ggplot(dat, aes(x=strain, y=count,group=id))+
geom_point(aes(col=feature), size=10, position = position_dodge(width = 0.5))+
geom_path(position = position_dodge(width = 0.5))+ theme_minimal()
问题是无论width
我在position_dodge()
. geom_beeswarm
产生一个更好看的情节:
library(ggbeeswarm)
ggplot(dat, aes(x=strain, y=count,group=id))+
geom_beeswarm(aes(col=feature), size=10, cex=6.5)+
geom_path(position = position_dodge(width = 0.5))+ theme_minimal()
但与的联系geom_path
分崩离析。这些行应该连接具有相同 ID 的记录。
有没有办法使geom_path
对应geom_beeswarm
点?或者,有没有办法调整geom_point
到等间距的点,比如geom_beeswarm
?
解决方案
推荐阅读
- bash - 我需要在启动树莓派时运行终端命令
- regex - 正则表达式范围,包括 -100 和 100 之间的负十进制数,包括但不要求 2 个小数点
- macos - Flutter 桌面 Podfile 丢失(flutter run -d macOS)
- ios - 在与 iOS 中的调用者相同的线程上运行回调
- android - Flutter:StreamBuilder 没有使用 Firebase 返回我的流
- r - 在读取 csv 文件之前删除两个文件夹之间不匹配的 csv 文件
- ios - iOS UIWebview 错误插件处理负载:无法播放从 android 设备上传的 s3 存储桶 url 中的视频
- react-native - React Native - 在制作动画时更改屏幕内容
- php - 电子邮件发送重复
- node.js - 使用 pm2 运行项目时出现 MongoDB 错误