cover_image

jjPlot 绘制分半提琴和箱线图

JunJunLab 老俊俊的生信笔记
2022年08月14日 10:43


图片

1引言

使用 jjPlot 尝试绘制多组的小提琴和箱线图的分半搭配图形。

安装:

# install.packages("devtools")
devtools::install_github("junjunlab/jjPlot")

2常见箱线图

library(jjPlot)
library(ggplot2)
library(reshape2)
library(tidyverse)

df <- read.csv('test.csv')

# check
head(df,3)

#           p1        p2           p3          p4         p5          p6  type  loc
# 1 0.08542618 0.1012627 0.0118642220 0.000107231 0.78682334 0.014516349 small abro
# 2 0.40841866 0.1969131 0.0267362910 0.000379649 0.15195617 0.215596125 small abro
# 3 0.57779365 0.3781431 0.0000000661 0.000008250 0.04334689 0.000708036 small abro

# wide to long
dfc <- melt(df,id.vars = c('type','loc'))

# normal boxplot
ggplot(dfc,aes(x = loc,y = value,fill = variable)) +
  geom_geom_boxplot()
图片

3分半图形

# plot
ggplot(dfc,aes(x = loc,y = value,fill = variable)) +
  geom_jjviolin(width = 0.1,
                trim = F,
                type = 'left',
                shift = 0.005,
                position = position_dodge(width = 0.8)) +
  geom_jjboxplot(width = 0.3,
                 type = 'left',
                 shift = 0.005,
                 position = position_dodge(width = 0.8)) +
  scale_fill_brewer(palette = 'Set1') +
  theme_bw(base_size = 16)
图片

4分半小提琴图

或者可以单纯的展示分半的小提琴图:

table(dfc$variable)
# p1 p2 p3 p4 p5 p6
# 40 40 40 40 40 40

# add types
dfc$type <- rep(rep(c('left','right'),each = 40),3)

# plot
ggplot(dfc,aes(x = loc,y = value)) +
  geom_jjviolin(aes(fill = variable,type = type),
                trim = F,
                width = 0.2,
                shift = -0.025,
                position = position_dodge(width = 0.8)) +
  scale_fill_brewer(palette = 'Set1') +
  theme_bw(base_size = 16)
图片



图片


   (微信交流群需收取20元入群费用,一旦交费,拒不退还!(防止骗子和便于管理))




图片



图片





  





ggplot 如何修改及自定义图例

jjPlot 让你的图原地裂开

grid 绘制小提琴图

jjAnno 添加加减符号注释

环形聚类树绘制

GseaVis 的一些新功能

这居然是小学生的题目?

ggplot 构建箱线图图层函数示例

ggplot 构建线段箭头图层函数示例

关于构建 ggplot 图层函数的映射问题

...

R绘图 · 目录
上一篇ggplot 如何修改及自定义图例下一篇jjPointPie 绘制 pie + pie
继续滑动看下一个
老俊俊的生信笔记
向上滑动看下一个