0 r scatter-plot categories ggplot2 categorical-data
我的数据被设置为一列包含连续值睾酮浓度,第二列包含四个"Kit类型"值中的一个,即"EIA","RIA","其他"或"全部".我想将试剂盒类型沿x轴分类,沿y的睾酮浓度.我似乎无法弄清楚如何在箱线图和散点图之间进行交叉,但是只有各个数据点和图表上标记的每个类别的中间标记?
这似乎让我把数据点变成了catagories,但是summarySE函数没有中位数:在R中使用ggplot2的平均段的分类散点图
没有数据,我只是在这里猜测,但......
## create some data
set.seed(42)
n <- 100
dat <- data.frame(Testo=rbeta(n, 2, 5),
Kit=sample(c('EIA', 'RIA', 'Other', 'All'), size = n, replace = TRUE))
## show unequal distribution of points, no problem
table(dat$Kit)
## All EIA Other RIA
## 23 30 14 33
## break into individual levels
dat2 <- lapply(levels(dat$Kit), function(lvl) dat$Testo[ dat$Kit == lvl ])
names(dat2) <- levels(dat$Kit)
## parent plot
boxplot(dat2, main = 'Testosterone Levels per Kit')
## adding individual points
for (lvl in seq_along(dat2)) {
points(jitter(rep(lvl, length(dat2[[lvl]]))), dat2[[lvl]],
pch = 16, col = '#88888888')
}
Run Code Online (Sandbox Code Playgroud)
