ggplot2 | 带p值的violin plot + jitter(云雨图)

1. 文章的效果图

Fig1C: https://www.nature.com/articles/s41586-023-06050-3
在这里插入图片描述
c, Left, fluorescence intensity quantifications of puncta of eGFP-tagged Cse4, Mmm1, Mdm12 and Mdm34, represented as dot plots and half-violin plots. Three experimental repeats are shown. Each data point is one punctum. Large dots represent the median and horizontal lines show MAD.

2. 模仿和代码

(1) 水平版本

在这里插入图片描述

install.packages("ggsignif") #显著性
install.packages("ggsci") #颜色
install.packages("ggdist") #云雨图:半个小提琴图,半个散点图jitter




# barplot with p====
library(ggplot2)
library(ggsignif) # 显著性标记

# 模拟数据
library(dplyr)
dat=iris[, c(1,2,3,5)]
colnames(dat)[1:3]=paste0("epi_", c(1:3))
plot.data=dat %>% tidyr::gather(key="celltype", value="value", -c("Species") )
head(plot.data)

# plot
ggplot(plot.data, aes(celltype, value)) + 
  # 如果不想安装ggdist包,使用这个也凑合
  #geom_violin( aes(fill=celltype, color=celltype), scale="width", show.legend = F )+
  ggdist::stat_halfeye(aes(color=celltype,fill=celltype), adjust = .5, 
                        width = .7, .width = 0, justification = -.2, point_colour = NA) + 
  geom_boxplot(aes(color=celltype),width = .2, outlier.shape = NA, show.legend = F) + #boxplot
  geom_jitter(aes(color=celltype),width = .05, alpha = .3)+ #散点图
  ggsci::scale_color_nejm()+ggsci::scale_fill_nejm() + #颜色
  coord_flip()+ xlab(" ")+theme_classic()+
  labs(title = "Expression Level ")+
  geom_signif(comparisons = list(
    c('epi_1', 'epi_2'), c('epi_2', 'epi_3'), 
    c('epi_1', 'epi_3')
                                 ),
    test = "wilcox.test",
    map_signif_level = F, ## p valuey
    y_position = c(7.5, 8, 8.5), #position
    size = 0.5, textsize = 4 )+
  theme(
    plot.title = element_text(size =15,hjust = 0.5, face="bold"), # #标题
    
    axis.text.x=element_text(size=15,face="bold",angle=0,hjust = 1,vjust = 1),
    axis.text.y=element_text(size=15,face="bold"),
    
    axis.title.x=element_text(size = 0,vjust = 1,face="bold"),
    axis.title.y=element_text(size = 15,face="bold")
    )

(2) 竖直版本

在这里插入图片描述


ggplot(plot.data, aes(celltype, value)) + 
  # 如果不想安装ggdist包,使用这个也凑合
  #geom_violin( aes(fill=celltype, color=celltype), scale="width", show.legend = F )+
  ggdist::stat_halfeye(aes(color=celltype,fill=celltype), adjust = .5, 
                       width = .7, .width = 0, justification = -.2, point_colour = NA) + 
  geom_boxplot(aes(color=celltype),width = .2, outlier.shape = NA, show.legend = F) + #boxplot
  geom_jitter(aes(color=celltype),width = .05, alpha = .3)+ #散点图
  ggsci::scale_color_nejm()+ggsci::scale_fill_nejm() + #颜色
  labs(x=" ", y="Expression Level", title="CD1234")+theme_classic()+
  geom_signif(comparisons = list(
      c('epi_1', 'epi_2'), c('epi_2', 'epi_3'), 
      c('epi_1', 'epi_3')
    ),
    test = "wilcox.test",
    map_signif_level = F, ## p valuey
    y_position = c(7.5, 8, 8.5), #position
    size = 0.3, textsize = 4 )+
  theme(
    plot.title = element_text(size =15,hjust = 0.5), # #标题
    
    axis.text.x=element_text(size=15,angle=30,hjust = 1,vjust = 1),
    axis.text.y=element_text(size=15),
    
    axis.title.x=element_text(size = 0,vjust = 1),
    axis.title.y=element_text(size = 15)
  )

Ref

  • https://mp.weixin.qq.com/s?__biz=Mzg3MDQ3MDI4Mg==&mid=2247497859&idx=1&sn=71d32ff3b0ed9f7eeb424f5742371ae6
  • xx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值