如何自定义geom_box绘图上的胡须线,与盒子的线条不同 [英] How to customize whisker lines on a geom_box plot differently than the lines of the box itself

查看:1030
本文介绍了如何自定义geom_box绘图上的胡须线,与盒子的线条不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于要求很高的最终用户,我需要了解 geom_box 图上的胡须线是否可以以不同于方块本身的颜色或类型进行着色?



考虑到



编辑评论之后:
我没有发现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()


解决方案

't发现问题user20650客气地指出。这是它的答案 - 两次绘制箱形图。

  ggplot(df,aes(x = factor(year),y = total ))+ 
geom_boxplot(linetype =dotted,color =red)+
geom_boxplot(aes(ymin = .. lower ..,ymax = .. upper ..))+
theme_bw()


Because of a demanding end user, I need to learn whether the whisker lines on a geom_box plot can be colored or typed differently than the box itself?

Having just considered boxplot with colored and dotted lines, I have created a minimal example.

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()

Can the plot below have green whiskers, keeping the red box, or solid whiskers keeping the dotted box?

This SO question tells us that base R permits whisker line customization aplenty. bxp has several parameters

EDIT after comment: I didn't spot the SO question user20650 graciously pointed out. Here is its answer -- plot boxplots twice.

ggplot(df, aes(x=factor(year), y=total)) + 
  geom_boxplot(linetype = "dotted", color = "red") +
  geom_boxplot(aes(ymin=..lower.., ymax=..upper..)) + 
  theme_bw()

解决方案

EDIT after comment: I didn't spot the SO question user20650 graciously pointed out. Here is its answer -- plot boxplots twice.

ggplot(df, aes(x=factor(year), y=total)) + 
  geom_boxplot(linetype = "dotted", color = "red") +
  geom_boxplot(aes(ymin=..lower.., ymax=..upper..)) + 
  theme_bw()

这篇关于如何自定义geom_box绘图上的胡须线,与盒子的线条不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆