博客地址:https://www.jianshu.com/u/619b87e54936
目录
R语言之可视化①误差棒
R语言之可视化②点图
R语言之可视化③点图续
R语言之可视化④点韦恩图upsetR
R语言之可视化⑤R图形系统
R语言之可视化⑥R图形系统续
R语言之可视化⑦easyGgplot2散点图
R语言之可视化⑧easyGgplot2散点图续
R语言之可视化⑨火山图
R语言之可视化⑩坐标系统
R语言之可视化①①热图绘制heatmap
R语言之可视化①②热图绘制2
R语言之可视化①③散点图 拟合曲线
R语言之可视化①④一页多图(1)
R语言之可视化①⑤ROC曲线
R语言之可视化①⑥一页多图(2)
R语言之可视化①⑦调色板
R语言之可视化①⑧子图组合patchwork包
R语言之可视化①⑨之ggplot2中的图例修改
R语言之可视化(20)之geom_label()和geom_text()
R语言之可视化(21)令人眼前一亮的颜色包
R语言之可视化(22)绘制堆积条形图
R语言之可视化(23)高亮某一元素
R语言之可视化(24)生成带P值得箱线图
R语言之可视化(25)绘制相关图(ggcorr包)
R语言之可视化(26)ggplot2绘制饼图
R语言之可视化(27)通过R语言制作BBC风格的精美图片
R语言之可视化(28)蜜蜂图
蜜蜂图
蜜蜂图beeswarm 是R语言的附加软件包。 与大多数R软件包一样,* beeswarm *可以从CRAN(http://cran.r-project.org/)获得。蜜蜂图beeswarm是类似于“带状图”stripchart的一维散点图,不同之处在于,蜜蜂图beeswarm重叠的点是分开的,因此每个点都是可见的。
示例
带状图stripchart vs. 蜜蜂图beeswarm
代码语言:javascript复制stripchart(decrease ~ treatment, data = OrchardSprays,
vertical = TRUE, log = "y", method = 'jitter', jitter = 0.2, cex = 1,
pch = 16, col = rainbow(8),
main = 'stripchart')
beeswarm(decrease ~ treatment, data = OrchardSprays,
log = TRUE, pch = 16, col = rainbow(8),
main = 'beeswarm')
指定点的颜色
代码语言:javascript复制data(breast)
beeswarm(time_survival ~ ER, data = breast,
pch = 16, pwcol = 1 as.numeric(event_survival),
xlab = "", ylab = "Follow-up time (months)",
labels = c("ER neg", "ER pos"))
legend("topright", legend = c("Yes", "No"),
title = "Censored", pch = 16, col = 1:2)
根据相关指标排序图片
代码语言:javascript复制## Generate some random data
set.seed(123)
distro <- list(runif = runif(100, min = -3, max = 3),
rnorm = rnorm(100))
for (m in c("swarm", "center", "hex", "square")) {
beeswarm(distro,
col = 2:3, pch = 16,
method = m,
main = paste('method = "', m, '"', sep = ''))
}
Compare the five "corral" methods
代码语言:javascript复制for (ii in c("none", "gutter", "wrap", "random", "omit")) {
beeswarm(distributions,
pch = 21, col = 2:4, bg = "#00000050",
corral = ii,
main = paste('corral = "', ii, '"', sep = ''))
}
将蜜蜂图与箱型图结合
代码语言:javascript复制 boxplot(len ~ dose, data = ToothGrowth,
outline = FALSE, ## avoid double-plotting outliers, if any
main = 'boxplot beeswarm')
beeswarm(len ~ dose, data = ToothGrowth,
col = 4, pch = 16, add = TRUE)
beeswarm(len ~ dose, data = ToothGrowth,
col = 4, pch = 16,
main = 'beeswarm bxplot')
bxplot(len ~ dose, data = ToothGrowth, add = TRUE)
调节蜜蜂图的点分布类型
代码语言:javascript复制 beeswarm(distributions, col = 2:4,
main = 'Default')
beeswarm(distributions, col = 2:4, side = -1,
main = 'side = -1')
beeswarm(distributions, col = 2:4, side = 1,
main = 'side = 1')
beeswarm(distributions, col = 2:4, priority = "descending",
main = 'priority = "descending"')
beeswarm(distributions, col = 2:4, priority = "random",
main = 'priority = "random"')
beeswarm(distributions, col = 2:4, priority = "density",
main = 'priority = "density"')
其他示例
代码语言:javascript复制if(!require(beeswarm)) install.packages(beeswarm)
data(breast)
beeswarm(time_survival ~ event_survival, data = breast,
method = 'swarm',
pch = 16, pwcol = as.numeric(ER),
xlab = '', ylab = 'Follow-up time (months)',
labels = c('Censored', 'Metastasis'))
legend('topright', legend = levels(breast$ER),
title = 'ER', pch = 16, col = 1:2)</pre>
代码语言:javascript复制beeswarm(time_survival ~ event_survival, data = breast,
method = 'swarm',
pch = 16, pwcol = as.numeric(ER),
xlab = '', ylab = 'Follow-up time (months)',
labels = c('Censored', 'Metastasis'))
boxplot(time_survival ~ event_survival, data = breast, add = T, names = c("",""), col="#0000ff22")