查看原文
其他

ggplot 绘制箱线图

JunJunLab 老俊俊的生信笔记 2022-08-15

点击上方,关注老俊俊!

1引言

ggplot 绘制一个箱线图看看。

2画图

加载内置数据:

library(ggplot2)
library(ggpubr)
library(tidyverse)

data("mtcars")

# 星号显示
symnum.args <- list(cutpoints = c(00.00010.0010.010.051),
                    symbols = c("****""***""**""*""ns"))

画图:

# plot
ggplot(mtcars,aes(x = factor(cyl),y = mpg)) +
  # errorbar
  stat_boxplot(aes(color = factor(cyl)),
               geom ='errorbar',width = 0.2,size = 0.8,) +
  # boxplot
  geom_boxplot(aes(color = factor(cyl)),
               width = 0.5,
               notch = T,
               notchwidth = 0.5,
               outlier.color = 'white',
               size = 0.8) +
  # line
  geom_line(data = media_val,
            aes(x = factor(cyl),y = mval,group = 1),
            size = 1) +
  # jitter
  geom_jitter(aes(color = factor(cyl)),
              size = 3,alpha = 0.5,
              position = position_jitter(width = 0.2)) +
  theme_classic(base_size = 18) +
  # 主题调整
  theme(aspect.ratio = 1.5,
        axis.text.x = element_text(angle = 45,hjust = 1,color = 'black',size = 16),
        legend.position = 'none') +
  # 颜色
  scale_color_brewer(palette = 'Set1') +
  # x轴标签
  scale_x_discrete(label = c('group1','group2','group3')) +
  xlab('') +
  # 差异检验
  stat_compare_means(comparisons = list(c('4','6'),c('4','8'),c('8','6')),
                     label.y = 38,size = 5,
                     step.increase = 0.13,
                     symnum.args =symnum.args)




  老俊俊生信交流群 ,QQ,


老俊俊微信:


知识星球:



今天的分享就到这里了,敬请期待下一篇!

最后欢迎大家分享转发,您的点赞是对我的鼓励肯定

如果觉得对您帮助很大,赏杯快乐水喝喝吧!



  





python 查找字符串

tornadoplot 绘制富集热图

m6A metagene distribution 计算详解

跟着 nature cell biology 学绘图-小提琴图

跟着 CNS 学绘图-带阴影背景条形图

如何上传质谱数据到 ProteomeXchange 官网

epistack 优雅的可视化你的基因区域

python 学习之 pandas 读取文本数据

python  pandas -

ribotish 质控结果复现及重新绘制

◀...


您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存