气泡图绘制教程

一边学习,一边总结,一边分享!

本期教程

封面

获得往期教程Data and Code,请在后台回复:20240809。请大家看清楚回复关键词,每天都有很多人回复错误关键词,我这边没时间和精力一一回复。


2022年教程总汇

https://mp.weixin.qq.com/s/Lnl258WhbK2a8pRZFuIyVg

2023年教程总汇

https://mp.weixin.qq.com/s/wCTswNP8iHMNvu5GQauHdg

2024年更新文档

2024年1月份更新文档

2024年2月份更新文档

2024年3月份更新文档

2024年4月份更新文档

2024年5月份更新文档

2024年6月份更新文档

2024年7月份更新文档

Code

1. 此脚所需文件


Data01

Data02_sample_key


2. 数据处理和计算

##'@导入所需的R包
library(tidyverse)
library(viridis)
library(reshape2)

#Import Data
#Data in COSMIC fit
data <- read.table(file="data01.txt",
                   header = TRUE, row.names = 1)

#Transpose so that each sample = 1 column
data <- as.data.frame(t(data))
#Convert Mutation Counts to Relative Contribution
data_relative <- scale(data, center = FALSE, scale = colSums(data))
head(colSums(data_relative))
#Restore Format
data_relative <- as.data.frame(t(data_relative))
data_relative <- tibble::rownames_to_column(data_relative, var="Samples")

#Import Sample Key
sample_key <- read.csv(file="data02-sample_key.csv")

data_relative=data_relative[order(data_relative$Samples),]
sample_key=sample_key[order(sample_key$Sample),]
data_relative$Cohort <- sample_key$Cohort[sample_key$Sample %in% data_relative$Samples]

#Remove Cohorts with less than 5 cases
data_relative <- filter(data_relative, Cohort != "Cervix-AdenoCA" & Cohort != "Breast-DCIS" & Cohort != "Myeloid-MDS")

#Select Columns to Plot
sbs40_data_relative <- as.data.frame(data_relative[,(c(1,48,47,49,64))])

#Create Proportions
sbs40_proportions <- sbs40_data_relative %>% 
  group_by(Cohort) %>% 
  summarise(
    SBS40a = sum(SBS40a >0)/n(), 
    SBS40b = sum(SBS40b >0)/n(), 
    SBS40c= sum(SBS40c >0)/n(), 
  )

#Summarise (SBS40 Signatures, Relative)
summary <- sbs40_data_relative %>% group_by(Cohort) %>% summarise_if(is.numeric, mean)

#Melt
sbs40_proportions <- melt(sbs40_proportions)
summary_melt <- melt(summary)

#Combine
summary_melt$prop = sbs40_proportions$value
  1. 获得绘图数据summary_melt
> head(summary_melt)
           Cohort variable      value      prop
1 Biliary-AdenoCA   SBS40a 0.22762994 0.5428571
2     Bladder-TCC   SBS40a 0.04237746 0.1304348
3     Bone-Benign   SBS40a 0.08948290 0.2500000
4      Bone-Epith   SBS40a 0.28331677 0.6000000
5 Bone-Osterosarc   SBS40a 0.05965147 0.1714286
6  Breast-AdenoCA   SBS40a 0.23385891 0.6000000
  1. 绘制基础图形
ggplot(summary_melt, aes(x = Cohort, y = fct_rev(variable))) +
  geom_point(aes(fill = value,  size = prop), color = "black", shape = 21) +
  scale_fill_viridis() +
  theme_bw() +
  theme(axis.title.x = element_blank()) +
  theme(axis.title.y = element_blank()) +
  theme(axis.text.x = element_text(angle = 45, hjust=1, size = 6)) +
  theme(axis.text.y = element_text(size = 6)) +
  labs(size="Percentage of Cases\nwith Signature", fill="Mean Relative\nAttribution") +
  theme(legend.position="bottom") +
  theme(legend.text=element_text(size=6)) +
  theme(legend.title=element_text(size=6))

  1. 使用geom_rect(),添加标识。
ggplot(summary_melt, aes(x = Cohort, y = fct_rev(variable))) +
  ##'@添加灰色条带
  geom_rect(ymin = 0, ymax = 4, xmin = 16.5, xmax = 17.5,
            alpha = 1, color = "black", fill = "grey75", linewidth = 0.25) +
  ##
  geom_point(aes(fill = value,  size = prop), color = "black", shape = 21) +
  scale_fill_viridis() +
  theme_bw() +
  theme(axis.title.x = element_blank()) +
  theme(axis.title.y = element_blank()) +
  theme(axis.text.x = element_text(angle = 45, hjust=1, size = 6)) +
  theme(axis.text.y = element_text(size = 6)) +
  labs(size="Percentage of Cases\nwith Signature", fill="Mean Relative\nAttribution") +
  theme(legend.position="bottom") +
  theme(legend.text=element_text(size=6)) +
  theme(legend.title=element_text(size=6))

若我们的教程对你有所帮助,请点赞+收藏+转发,这是对我们最大的支持。

往期部分文章

1. 最全WGCNA教程(替换数据即可出全部结果与图形)


2. 精美图形绘制教程

3. 转录组分析教程

4. 转录组下游分析

小杜的生信筆記 ,主要发表或收录生物信息学教程,以及基于R分析和可视化(包括数据分析,图形绘制等);分享感兴趣的文献和学习资料!!

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小杜的生信筆記

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值