【发布时间】:2015-03-31 15:17:28
【问题描述】:
由于要求苛刻的最终用户,我需要了解geom_box 绘图上的须线是否可以与框本身不同的颜色或类型?
刚刚考虑了boxplot with colored and dotted lines,我创建了一个最小的示例。
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()
下面的图可以有绿色胡须,保留红色框,还是实心胡须保留虚线框?
这个 SO 问题告诉我们,base R 允许大量定制晶须线。 bxp has several parameters
评论后编辑: 我没有发现 user20650 优雅地指出的 SO 问题。这是它的答案——绘制箱线图两次。
ggplot(df, aes(x=factor(year), y=total)) +
geom_boxplot(linetype = "dotted", color = "red") +
geom_boxplot(aes(ymin=..lower.., ymax=..upper..)) +
theme_bw()
【问题讨论】:
-
如果这确实回答了您的问题,您应该将其作为答案提交,而不是将其编辑到您的问题中。
-
@Gregor,谢谢。我从来没有使用过自我回答的方法。奇怪的是,user20650 的评论被删除了。我想举报这条评论。