From 14e8118c15fd89f362c9d30543c409b35eb0ed43 Mon Sep 17 00:00:00 2001 From: Lulu Shi Date: Sat, 17 Jun 2023 11:12:45 +0800 Subject: [PATCH] Update plot_Hap_pheatmap.r --- plot_Hap_pheatmap.r | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/plot_Hap_pheatmap.r b/plot_Hap_pheatmap.r index 509d030..baf5a7e 100644 --- a/plot_Hap_pheatmap.r +++ b/plot_Hap_pheatmap.r @@ -1,26 +1,21 @@ # 不同组之间有缝隙,更加直观 library(pheatmap) -group = read.table("sample_plot.list.txt", stringsAsFactors = F) ##两列,1:ID,2:品种 -names(group) <- c("ID","Group") -rownames(group) <- group$ID -group$ID <- NULL +group = read.table("sample_plot.list.txt", row.names=1, stringsAsFactors = F) # 两列,1:ID,2:品种,ID与txt文件顺序一致 +names(group) <- c("Group") -new_order <- c("JPBC", "Mongolian", "Kazakh", "Yanbian") # 新的组顺序 -group$Group <- factor(group$Group, levels = new_order) +data=read.table("LRP2BP.SNP.biallele.txt",header=TRUE, stringsAsFactors = F) # 转置后的文件 +data=data.matrix(data) -data2=read.table ("LRP2BP.SNP.biallele.txt", header = TRUE, stringsAsFactors = F) # 转置后的文件 -data2=data.matrix(data2) - -annotation_row = data.frame(Group=as.vector(group$Group)) -rownames(annotation_row) = rownames(data2) - -names(rowcol) <- unique(annotation_row) -ra_col <- list(Group=c(JPBC="#873186", Mongolian="#E20593", Kazakh="#6BB93F", Yanbian="#18A2CA")) +an_row = data.frame(Group=as.vector(group$Group)) +rownames(an_row)=rownames(data) +ra_col <- list(Group=c(JPBC="#873186",Mongolian="#E20593", + Kazakh="#6BB93F",Yanbian="#18A2CA")) # "#3364BC", "#000000", "#F37020", "#DBB71D" gap_line <- c(11,21,32) # 数量划分,分开每组的热图 -pheatmap(data2,annotation_row = annotation_row, annotation_colors = ra_col, - cluster_row = FALSE,cluster_col = FALSE, - gaps_row=gap_line,legend =FALSE, - labels_col = rep("",ncol(data2)),labels_row=rep("",nrow(data2)), - color=c("#F7F8D5", "#BF3826"), angle_col = "0") +pheatmap(data,cluster_row=F,cluster_col=F,legend=F, + show_rownames=FALSE,show_colnames=FALSE, + annotation_legend=T,annotation_names_row=T, + annotation_row=an_row,annotation_colors=ra_col, + gaps_row=gap_line, + color=c("#F7F8D5", "#BF3826"))