虚线除了geom_box中的异常值外 [英] dotted lines in addition to outlier in geom_box

查看:124
本文介绍了虚线除了geom_box中的异常值外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将虚线末端的虚线和水平条添加到ggplot中的boxplot中?
默认情况下,它会从框中创建一条垂直线条。请看下面的例子,我是怎么想的:



这里是我的代码

  p <-ggplot(data,aes(factor(Length,levels = 18:26),logFC))+ 
geom_boxplot(fill =white)+
coord_cartesian(ylim = c -5,5))+
theme_bw(base_size = 45)+
scale_x_discrete(,breaks = factor(18:26),drop = FALSE)

解决方案

@CMichael引用了答案。这仅仅说明了它。首先是一些玩具数据。

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


How do I add dotted lines and horizontal bars at the end of the dotted lines to my boxplot in ggplot? By default it creates a vertical lines going out from the box. Please see example below how I want it:

here is my code

  p <- ggplot(data, aes(factor(Length,levels=18:26), logFC)) + 
         geom_boxplot(fill = "white") + 
         coord_cartesian(ylim=c(-5,5)) +
         theme_bw(base_size=45) + 
         scale_x_discrete("", breaks=factor(18:26), drop=FALSE) 

解决方案

@CMichael cites the answer. This merely illustrates it. First, some toy data.

year <- rep("2014", 10)
total <- c(seq(55, 90, 5), 100, 40)
df <- data.frame(year = as.factor(year), total = total)

Then the plot, showing dotted lines and color.

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

这篇关于虚线除了geom_box中的异常值外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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