【发布时间】:2018-05-21 09:21:05
【问题描述】:
我想使用 ggplot 绘制一个分组箱线图。如下图所示:
请看下面我的数据中的一个示例(10 行):
alpha colsample_bytree best_F1
35 0.00 0.5 0.5825656
78 0.10 0.3 0.4716612
68 0.00 0.3 0.4714286
27 0.40 1.0 0.4786216
49 0.15 0.5 0.4943968
62 0.00 0.3 0.4938805
70 0.00 0.3 0.4849785
73 0.10 0.3 0.4997061
59 0.30 0.5 0.4856369
88 0.20 0.3 0.4552402
sort(unique(data$alpha))
0 0.1 0.15 0.2 0.3 0.4
sort(unique(data$colsample_bytree))
0.3 0.5 1
我的代码如下:
library(ggplot2)
library(ggthemes)
ggplot(data, aes(x= colsample_bytree, y = best_F1, fill = as.factor(alpha))) +
geom_boxplot(alpha = 0.5, position=position_dodge(1)) + theme_economist() +
ggtitle("F1 for alpha and colsample_bytree")
这会产生以下情节:
以及以下警告:
Warning message:
"position_dodge requires non-overlapping x intervals"
由于变量 colsample_bytree 采用 3 个离散值,而变量 alpha 采用 6,我希望看到 3 组箱线图——每个组由 6 个箱线图组成,对应于不同的 alpa 值,每个组位于不同的 colsample_bytree 值,IE 0.3、0.5 和 1。
我希望箱线图不会像我引用的示例那样重叠。
【问题讨论】:
-
顶部的示例使用分类 x 轴