我的数据被设置为一列包含连续值睾酮浓度,第二列包含四个" Kit类型中的一个"值是" EIA," " RIA," "其他,"或者"全部。"我想将试剂盒类型沿x轴分类,沿y的睾酮浓度。我似乎无法弄清楚如何在箱线图和散点图之间进行交叉,但是只有各个数据点和图表上标记的每个类别的中间标记?
这似乎让我的数据点变成了catagories,但是summarySE函数没有中位数:Categorical scatter plot with mean segments using ggplot2 in R
答案 0 :(得分:5)
没有数据,我只是在这里猜测,但是......
## 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')
}