热
使用 jjPlot 尝试绘制多组的小提琴和箱线图的分半搭配图形。
安装:
# install.packages("devtools")
devtools::install_github("junjunlab/jjPlot")
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()
# 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)
或者可以单纯的展示分半的小提琴图:
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元入群费用,一旦交费,拒不退还!(防止骗子和便于管理)
)。
老俊俊微信:
知识星球:
所以今天你学习了吗?
最后欢迎大家分享转发,您的点赞是对我的鼓励和肯定!
如果觉得对您帮助很大,赏杯快乐水喝喝吧!
往期回顾
◀...