在可爱的 Rui Barradas 的帮助下,我能够循环浏览多个列并创建带有标记异常值的箱线图。目前,我正在尝试使用以下代码将这些异常值输出到向量中:
ClusterRepVector <- character()
i_num = which(sapply(tpose_genexp, is.numeric)) #
str(tpose_genexp[i_num])
i_num <- i_num[c(1, 4, 5)]
lapply(names(tpose_genexp[i_num]), \(x) {
bp <- boxplot(tpose_genexp[[x]],
horizontal = FALSE, # Horizontal or vertical plot
lwd = 2, # Lines width
col = rgb(1, 0, 0, alpha = 0.4), # Color
main = x,
notch = TRUE,
border = "black",
outpch = 25, # Outliers symbol
outbg = "green", # Outliers color
whiskcol = "blue", # Whisker color
whisklty = 2, # Whisker line type
lty = 1 ) # Line type (box and median)
i_row = which(tpose_genexp[[x]] %in% bp$out)
labs = if(length(i_row)) {
tapply(row.names(tpose_genexp)[i_row], bp$out, paste, collapse = ", ")
} else ""
text(1.1, unique(bp$out), labels = labs, pos = 4)
outliername = c(row.names(tpose_genexp)[i_row])
ClusterRepVector = c(ClusterRepVector, outliername)
})