SAS繪圖、R繪圖哪個(gè)更適合你? (二):R繪圖鑒賞
? 前面我們一起鑒賞了SAS的繪圖本領(lǐng),今天我們來(lái)領(lǐng)略R的繪圖風(fēng)采,兩者各有千秋!后續(xù)將會(huì)一一更新繪圖教程,包括圖中的每個(gè)細(xì)節(jié)調(diào)整,關(guān)鍵的Code講解,致力于共同學(xué)習(xí)進(jìn)步,打造高質(zhì)量圖表!
? 下期我們將會(huì)就R和SAS兩款統(tǒng)計(jì)分析軟件的繪圖功能進(jìn)行對(duì)比,從繪圖對(duì)于科研的重要性到繪圖的原理,以及如何才算學(xué)會(huì)了繪圖這門(mén)技巧進(jìn)行詳細(xì)講解。
1.1?相關(guān)圖
熱圖
pvalue <- matrix(ifelse(dfP <= 0.001, "***",?
? ? ? ? ? ifelse(dfP <= 0.01, "**",? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
ifelse(dfP <= 0.05, "*", " "))), nrow = nrow(dfspearman))
setwd("E:/DATA/TP/20230511-4500/FIG")
png("Heatmap4.png",units="in", width=10, height=8,res=400)
pheatmap(??
dfspearman,?
angle_col = 45,??
color = colorRampPalette(c("#3C5488", "#FFFFFF", "#E64B35"))(50),??
show_rownames = T,?
display_numbers =pvalue,number_color="black",number_format="%.2e", fontsize_number = 16,?
col_names_side = "top",??
show_colnames =T,??
fontfamily= "myFont",??
border = F,??
# cluster_rows = FALSE,??
?cluster_cols? = FALSE,??
fontsize = 16,??
fontsize_row=16,??
fontsize_col=16
)
dev.off()

網(wǎng)絡(luò)圖和弦圖
library(showtext)
showtext_auto(enable = T)
nodegroup<-as.data.frame(cbind(Id=unique(c(df$x,df$y))))
#write.table(nodegroup,'node1.txt',row.names = F,sep = '\t',quote = F,fileEncoding = 'GB2312')
node1<-c('HRDB'=? '#fb0d1c',
'VR'=? '#b4701d','
2s'=? '#c56cfb',
'pc'=? '#c56cfb',
'pNd'=? '#c56cfb',
'24e'=? '#44fffc',
'rMf'=? '#44fffc',
'rMSg'=? '#44fffc',
'2s'? ='#f8bf6e',
'Hk'=? '#f8bf6e',
'Ho'? ='#f8bf6e',
'24-LF'=? '#fc665d',
'LF'=? '#fc665d',
'L'? ='#fc665d',
'24-LF/HF'=? '#77d07a',
'LF/'? ='#77d07a',
'24-SDNN'? ='#77d07a',
'SDN'? ='#78c7ec',
'SDNN'? ='#78c7ec')
nodegroup$color1<-node1[nodegroup$Id]
pdf('circos2.pdf',width = 5,height = 6)
circos.clear()
circos.par("track.height" = 0.3,? ? gap.after=c(5,5,rep(1,2),5,rep(1,2),5,rep(1,2),5,rep(1,2),5,rep(1,2),5,rep(1,1),5),
?start.degree=90)
circos.initialize(factors =nodegroup$Id,xlim = c(0,1))
length(get.all.sector.index())
circos.track(ylim = c(0,1),bg.border=NA)
circos.trackPlotRegion(??
track.index = 2,??
ylim = c(0, 1),? ?
track.height = 0.06, bg.border = 'black', bg.col =node1,
? panel.fun = function(x, y) {
sector.index = get.cell.meta.data('sector.index')
xlim = get.cell.meta.data('xlim')
ylim = get.cell.meta.data('ylim')? ??
circos.text(CELL_META$xcenter,?
CELL_META$cell.ylim[2]+1 ,? ? ? ? ? ? ? ??
CELL_META$sector.index,? ? ? ? ? ? ? ??
facing = "reverse.clockwise",? ? ? ? ? ? ? ? ?
adj = c(1,0),? ? ? ? ? ? ? ?
?niceFacing = TRUE,? ? ? ? ? ? ? ?
?cex = 0.6)??
} )
nodecolor<-nodegroup$color1
names(nodecolor)<-nodegroup$Id
col_meth<- colorRamp2(c(0.1, 0.5, 0.9), c('#0b24fb','#feb7c2', '#fc0d1b'))
for(i in 1:nrow(df)){??
circos.link(df$x[i], 0.5, df$y[i], 0.5,? ? ? ? ? ? ??
lwd=df$r[i]*2,? ? ? ? ? ? ??
col = col_meth(df$r[i]))
}
library(ComplexHeatmap)
lgd_links = Legend(at = c(0.1, 0.5, 0.9), col_fun = col_meth,? ? ? ? ? ? ? ? ? ? title_position = "topleft",? ? ? ? ? ? ? ? ? ?
title='Correlation')
lgd_list_vertical = packLegend(lgd_links)
draw(lgd_list_vertical, x = unit(4, "mm"), y = unit(4, "mm"), just = c("left", "bottom"))
dev.off()




基因互作圖

1.2 聚類(lèi)圖
復(fù)雜熱圖
groupcolor <- c("#2878B5","#C82423")
names(groupcolor) <- c("pre","post") #color1
agecolor <- c("#008000","#3cb371","#84c09c","#5e8e7e")
names(agecolor) <- c("1","2","3","4") #color2
contentcolor <-c("#8ECFC9","#FFBE7A","#FA7F6F",'#82B0D2')
names(contentcolor) <- c("Th1","Th2","Th17/Th22","Multi") #color3
ann_colors <- list(Group=groupcolor, Content= contentcolor,Age=agecolor) #Color Summary List####heatmap####
library(pheatmap)windowsFonts(myFont = windowsFont("Times New Roman"),? ? ? ? ? ? ?KT = windowsFont("楷體"),? ? ? ? ? ? ?
ST = windowsFont("宋體"))?
setwd("E:/DATA/TP/20230511-4500/FIG")
png("Heatmap3.png",units="in", width=10, height=8,res=400)
pheatmap(? df,? color = colorRampPalette(c("#3C5488", "#FFFFFF", "#E64B35"))(50),?
show_rownames = T,??
show_colnames =F,??
annotation_row = dfgroup1,??
annotation_col = dfgroup2,??
fontfamily= "myFont",??
annotation_colors = ann_colors,??
border = F,
? ?cluster_rows = FALSE,
? ?cluster_cols? = FALSE,
? fontsize = 16,
? fontsize_row=16,
? fontsize_col=16
)
dev.off()

PCA可視化圖

冷熱點(diǎn)聚集性分析地圖

1.3 展示模型中變量效應(yīng)量的圖
機(jī)器學(xué)習(xí)中特征度可視化


條件過(guò)程分析效應(yīng)圖

森林圖

點(diǎn)線(xiàn)圖

非線(xiàn)性模型

風(fēng)險(xiǎn)分?jǐn)?shù)圖

列線(xiàn)圖

1.4 數(shù)據(jù)挖掘展示圖
詞云圖

堆積圖

箱線(xiàn)圖

散點(diǎn)圖


氣泡圖

1.5 機(jī)器學(xué)習(xí)
模型性能驗(yàn)證折線(xiàn)圖

驗(yàn)證集區(qū)分度測(cè)試圖

“黑盒”模型重要特征可視化



校正曲線(xiàn)與DCA曲線(xiàn)
? setwd("D:/DATA/TP/20230527-COX-LASSO/FIG")
? png("DCA2.png",units="in", width=6, height=6,res=400)
dca(Surv(Survival_time, Death) ~ Nomogram1,
? ? ? ? ? ? ? ? ? ? ? ? ?data = df,
? ? ? ? ? ? ? ? ? ? ? ? ?time =90,
? ? ? ? ? ? ? ? ? ? ? ? thresholds = 1:100/ 100) %>%
? plot(smooth = T,lwd = 1.2)+theme_classic()+
# theme_prism(base_size =17)+
? ? theme(legend.position="top")+
? ? scale_x_continuous(
? ? ? limits = c(0, 0.85),
? ? ? guide = "prism_minor")+
?scale_colour_manual(values=c("blue","red","green","orange","grey"))+?
theme(axis.text.x = element_text(size=25,face="bold",colour = "black",family="A"))+? ?
theme(axis.text.y = element_text(size=25,face = "bold",colour = "black",family = "A"))+? ??
theme(axis.title.x = element_text(size=25,face="bold",colour = "black",family="A"))+? ??
theme(axis.title.y = element_text(size=25,face = "bold",colour = "black",family = "A"))
dev.off()
setwd("D:/DATA/TP/20230527-COX-LASSO/FIG")
png("DCA2.png",units="in", width=6, height=6,res=400)
dca(Surv(Survival_time, Death) ~ Nomogram0,
? ? data = df,
time =30,
thresholds = 1:100/ 100) %>%??
plot(smooth = T,lwd = 1.2)+theme_classic()+?
?# theme_prism(base_size =17)+??
theme(legend.position="top")+??
scale_x_continuous(
? ? limits = c(0, 0.85),
? ? guide = "prism_minor")+
scale_colour_manual(values= c("blue","red","green","orange","grey"))+? theme(axis.text.x = element_text(size=25,face="bold",colour = "black",family="A"))+??
theme(axis.text.y = element_text(size=25,face = "bold",colour = "black",family = "A"))+??
theme(axis.title.x = element_text(size=25,face="bold",colour = "black",family="A"))+??
theme(axis.title.y = element_text(size=25,face = "bold",colour = "black",family = "A"))
dev.off()


常用科研
# 暖色調(diào):#FF5733, #FFC300, #FFA012, #FF7F50, #FFB6C1
# 冷色調(diào):#87CEFA, #00BFFF, #1E90FF, #6495ED, #ADD8E6
# 土色調(diào):#8B4513, #A0522D, #D2691E, #CD853F, #F4A460
# 棕色調(diào):#8B6B23, #BC8F8F, #DEB887, #D2B48C, #F5DEB3
# 紫色調(diào):#9400D3, #8A2BE2, #9370DB, #BA55D3, #DA70D6
# 黃色調(diào):#FFD700, #FFFF00, #F0E68C, #FFC107, #FFA500
# 綠色調(diào):#00FF00, #32CD32, #3CB371, #2E8B57, #228B22
# 灰色調(diào):#808080, #A9A9A9, #C0C0C0, #D3D3D3, #E6E6E6
關(guān)注微信公眾號(hào),獲取更多相關(guān)內(nèi)容!

以上繪圖教程后續(xù)更新,如急需代碼,請(qǐng)后臺(tái)私信聯(lián)系!