--PHEATMAP_ Visualization Analysis of R-language drawing thermal graph

Source: Internet
Author: User

R language Drawing Hot Figure--pheatmap
Pheatmap profile: Pretty heatmaps--implementation of Heatmaps that offers more control over dimensions and appearance. [Plain] View plain copy library (pheatmap)    #创建数据集test测试矩阵    Test = matrix (Rnorm (200),  20, 10)    test[1:10, seq (1, 10, 2)] = test[1:10, seq (1,  10, 2)] + 3   test[11:20, seq (2, 10, 2)] = test[11:20,  seq (2, 10, 2)] + 2   test[15:20, seq (2, 10, 2)] =  Test[15:20, seq (2, 10, 2)] + 4   colnames (test)  = paste ("Test",  1:10, sep =  "")    rownames (test)  = paste ("Gene",  1:20, sep  =  "")    #  use Pheatmap function to draw hot diagram    pheatmap (test)    # The default parameter is to cluster the rows and columns (you can set Cluster_row = False, Cluster_col = False is not a row of clustering; If you do clustering, you can also set up treeheight_row=0, treeheight_col= 0 does not show Dendrogram), The matrix does notTo standardize (standardized parameters are scale, optional "none", "Row", "column"), each small block of the heat map is separated by a gray (parameter border_color, if you do not want to border can be set to Na, of course, can be set to other colors), Legend is displayed on the upper right (you can set legend = False to not show legend); The color of the hot chart can be adjusted by the parameters;
[Plain] View plain copy pheatmap (test, Cluster_row = FALSE, Legend_breaks = -1:4, Legend_labels = C ("0", [plain] View Plain copy "1e-4", "1e-3", "1e-2", "1e-1", "1") #可自己设置图例 #可设置参数display_numbers将数值显示在热图的格子中, you can format numeric values by Number_format, The more commonly used are "%.2f" (two digits after the decimal point), "%.1e" (scientific notation, keep a decimal point), Number_color set the color of the display content:
Pheatmap (test, display_numbers = TRUE, Number_format = "%.2f", number_color= "Purple") # "%.2f" means to retain the two-bit [plain] view after the decimal point Plai n Copy # display text in a hot pheatmap (test, display_numbers = True) pheatmap (test, Display_numbers = true, Number_format = "\%. 1e ") Pheatmap (test, display_numbers = Matrix (IfElse (Test > 5," * "," "), Nrow (test)) #还可以自己设定要显示的内容;


#pheatmap参数设置改变每个格子的大小
Pheatmap (test, cellwidth =, Cellheight =, main = "Example heatmap", FontSize = 8, filename = "test.pdf") #main可设置热图的 Title, FontSize set font size, filename can be directly hot survival out, support format PNG, PDF, TIFF, BMP, JPEG, and can be set through the width, height settings picture size; [Plain] View plain copy # Pheatmap can also display grouping information for rows or columns, support multiple groupings; Annotation_col = Data.frame (Celltype = factor (Rep (c ("CT1", "CT2"), 5), time = 1:5) Rown Ames (Annotation_col) = Paste ("Test", 1:10, Sep = "") Annotation_row = data.frame (Geneclass = factor (Rep (c ("Path1", " Path2 "," Path3 "), C (4, 6))) Rownames (Annotation_row) = Paste (" Gene ", 1:20, Sep =" ") Pheatmap (test, Annotatio N_col = annotation_col, Annotation_row = Annotation_row)

[Plain] View plain copy #设定各个分组的颜色 ann_colors = list (time = C ("White", "Firebrick"), #连续数值型分组可设置成渐变 Celltype = C (c T1 = "#1B9E77", CT2 = "#D95F02"), Geneclass = c (Path1 = "#7570B3", Path2 = "#E7298A", Path3 = "#66A61E")) Pheatmap (Test, Annotation_col = annotation_col, Annotation_row = annotation_row, annotation_colors = ann_colors)

#pheatmap还能够根据特定的条件将热图分隔开;
# cutree_rows, Cutree_cols: Separate the heat map according to the number of clustering;
Pheatmap (test,cutree_rows=3,cutree_cols=2)
[Plain] View plain copy #还可以自己设定各个分组的颜色 ann_colors = list (time = C ("White", "Firebrick"), #连续数值型分组可设置成渐变 Celltype = C (CT1 = "#1B9E77", CT2 = "#D95F02"), Geneclass = c (Path1 = "#7570B3", Path2 = "#E7298A", Path3 = "#66A61E")) PHE    Atmap (test, Annotation_col = annotation_col, Annotation_row = annotation_row, annotation_colors = ann_colors) #还可以利用gaps_row, Gaps_col set the position to separate pheatmap (test, Annotation_col = annotation_col, cluster_rows = FALSE, Gaps_row = C (a), Cutree_col = 2)



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.