How to customize whisker lines on a geom_box plot differently than the lines of the box itself

大城市里の小女人 提交于 2019-12-11 02:46:33

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/29372200/how-to-customize-whisker-lines-on-a-geom-box-plot-differently-than-the-lines-of

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!