最近年中匯總,會持續(xù)到6月底,我們就分享一些基礎(chǔ)知識!
我們的任務(wù)是實(shí)現(xiàn)下面這張圖

圖片.png
直接開始,讀取數(shù)據(jù)
library(Seurat)
library(ggplot2)
library(reshape2)
library(RColorBrewer)
library(ggalt)
colormap = colorRampPalatte(rev(brewer.pal(11,'RdYIBu')))(15)
Seurat_obj = readRDS(10X單細(xì)胞/空間seurat對象)
df = as.data.frame(t(as.matrix(Seurat_obj@assays$RNA@data)))[,感興趣的基因列表]
df$x = rownames(df)
dfData = melt(df,id = 'x')
開始繪制
ggplot(dfData,aes(x = x,y = value)) + geom_horizon(colour = NA,size = 0.25,bandwidth = 10) +
facet_warp(~variable,ncol =1 ,strip.position = 'left') +
scale_fill_manual(values = colormap) +
xlab('Barcode') + ###這里建議大家轉(zhuǎn)換一下,不要顯示barcode,轉(zhuǎn)換成cluster或者細(xì)胞類型
ybal('') +
theme_bw() +
theme(strip.background = element_blank(),
strip.text.y = element_text(hjust = 0 ,angle = 180,size = 10),
axis.text.y = element_blank(),
panel.grid = element_blank(),
panel.spacing.y = unit(-0.05,'lines'),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
axis.ticks.y = element_blank())
在這里我們大功告成,完成上面圖譜的繪制。
擴(kuò)展一下
使用ggplot2和ggalt包繪制世界地圖面板

20151229153826331.png
代碼如下
library(ggplot2) #需安裝最新的2.0.0版本
library(dplyr) #你也可以用內(nèi)置的subset函數(shù)來代替filter函數(shù)
library(ggalt) #安裝方法: devtools:install_github("hrbrmstr/ggalt")。需安裝加載devtools包
library(ggthemes)
world <- map_data("world")
world <- world[world$region != "Antarctica",] # 剔除南極洲
dat <- read.csv("CLIWOC15.csv")
dat <- filter(dat, Nation != "Sweden")
gg <- ggplot()
gg <- gg + geom_map(data=world, map=world,
aes(x=long, y=lat, map_id=region),
color="white", fill="#7f7f7f", size=0.05, alpha=1/4)
gg <- gg + geom_point(data=dat,
aes(x=Lon3, y=Lat3, color=Nation),
size=0.15, alpha=1/100)
gg <- gg + scale_color_tableau()
gg <- gg + coord_proj("+proj=wintri")
gg <- gg + facet_wrap(~Nation)
gg <- gg + theme_map()
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme(legend.position="none")
gg
基礎(chǔ)知識,多多學(xué)習(xí)