論文
Single-cell profiling of vascular endothelial cells reveals progressive organ-specific vulnerabilities during obesity
https://www.nature.com/articles/s42255-022-00674-x#Sec58
s42255-022-00674-x.pdf
https://github.com/Osynchronika/sc_EC_obesity_atlas
大部分 作圖的數據都有,可以試着用論文中提供的數據復現一下論文中的圖
今天的推文我們試着復現一下論文中的Figure2中的熱圖,figure2中有3個熱圖,按照複製程度排序是 figure2m figure2f 和figure2o
我們從最簡單的開始,先復現figure2m
論文中提供的數據如下
數據中有很多缺失值,看論文中的配色 我猜是把缺失值替換成0了,我不太確定這種處理方式是否可以
我把數據單獨複製到一個excel文件裏
給第一列添加一個表頭
代碼
讀取數據
library(readxl)
dat<-read_excel("data/20230207/figure2o.xlsx",na='NA')
dat
寬格式轉換爲長格式
library(tidyverse)
dat%>%
mutate(gene_name=factor(gene_name,levels = gene_name))%>%
pivot_longer(!gene_name)%>%
mutate(name=str_replace(name,'_logFC',''),
value=replace_na(value,0))%>%
mutate(name=factor(name,levels = c("sc","vis","liver",
"kidney","lung","heart","brain")))-> new.dat
熱圖代碼
library(ggplot2)
ggplot(data = new.dat,aes(x=gene_name,y=name))+
geom_tile(aes(fill=value),
color="black")+
theme_bw()+
theme(panel.border = element_blank(),
panel.grid = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
axis.text.x = element_text(angle=90,face="italic"),
axis.text.y = element_blank(),
legend.position = "bottom")+
scale_fill_gradient2(low="blue",mid="white",high = "red",
midpoint = 0,
breaks=c(-0.3,0,0.3),
name="log(FC)")+
guides(fill=guide_colorbar(title.position = "top",
title.hjust = 0.5,
barwidth = 10))+
coord_equal() -> p1
p1
左側的分組也用熱圖來實現,就是一個一列的熱圖
new.dat %>% filter(gene_name == "Apoe") %>%
ggplot(aes(x=gene_name,y=name))+
geom_tile(aes(fill=name),color="black")+
theme_bw()+
theme(panel.border = element_blank(),
panel.grid = element_blank(),
axis.ticks = element_blank(),
axis.text.x = element_blank(),
axis.title = element_blank(),
legend.position = "none",
axis.text.y = element_text(size=15,face="bold"))+
scale_x_discrete(expand=expansion(mult=c(0,0)))+
coord_equal() -> p2
p2
最後是拼圖
library(patchwork)
p2 + p1
示例數據和代碼可以給推文點贊,然後點擊在看,最後留言獲取
歡迎大家關注我的公衆號
小明的數據分析筆記本
小明的數據分析筆記本 公衆號 主要分享:1、R語言和python做數據分析和數據可視化的簡單小例子;2、園藝植物相關轉錄組學、基因組學、羣體遺傳學文獻閱讀筆記;3、生物信息學入門學習資料及自己的學習筆記!