由于最终用户的要求很高,我需要了解geom_box绘图上的须线是否可以与盒子本身不同的颜色或类型?
刚刚考虑了带有彩色和虚线的箱线图,我创建了一个最小的示例。
year <- rep("2014", 10)
total <- c(seq(55, 90, 5), 100, 40)
df <- data.frame(year = as.factor(year), total = total)
ggplot(df, aes(x=factor(year), y=total)) +
geom_boxplot(linetype = "dotted", color = "red") +
theme_bw()
Run Code Online (Sandbox Code Playgroud)
下面的图可以有绿色胡须,保留红色框,还是实心胡须,保留虚线框?

这个 SO 问题告诉我们,基础 R 允许大量的晶须线定制。 bxp有几个参数
评论后编辑:我没有发现 user20650 慷慨地指出的问题。这是它的答案——绘制箱线图两次。
ggplot(df, aes(x=factor(year), y=total)) +
geom_boxplot(linetype = "dotted", color = "red") +
geom_boxplot(aes(ymin=..lower.., ymax=..upper..)) +
theme_bw()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2613 次 |
| 最近记录: |