### Install and Initialize ggheatmap Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/README.md Install the package from GitHub or CRAN and prepare the sample data matrix and metadata. ```R devtools::install_github("XiaoLuo-boy/ggheatmap") install.packages("ggheatmap") library(ggheatmap) library(tidyr) set.seed(123) df <- matrix(runif(225,0,10),ncol = 15) colnames(df) <- paste("sample",1:15,sep = "") rownames(df) <- sapply(1:15, function(x)paste(sample(LETTERS,3,replace = F),collapse = "")) df[1:4,1:4] row_metaData <- data.frame(exprtype=sample(c("Up","Down"),15,replace = T), genetype=sample(c("Metabolism","Immune","None"),15,replace = T)) rownames(row_metaData) <- rownames(df) col_metaData <- data.frame(tissue=sample(c("Normal","Tumor"),15,replace = T), risklevel=sample(c("High","Low"),15,replace = T)) rownames(col_metaData) <- colnames(df) exprcol <- c("#EE0000FF","#008B45FF" ) names(exprcol) <- c("Up","Down") genecol <- c("#EE7E30","#5D9AD3","#D0DFE6FF") names(genecol) <- c("Metabolism","Immune","None") tissuecol <- c("#98D352","#FF7F0E") names(tissuecol) <- c("Normal","Tumor") riskcol <- c("#EEA236FF","#46B8DAFF") names(riskcol) <- c("High","Low") col <- list(exprtype=exprcol,genetype=genecol,tissue=tissuecol,risklevel=riskcol) text_rows <- sample(rownames(df),3) p<- ggheatmap(df,cluster_rows = T,cluster_cols = T,scale = "row", text_show_rows = text_rows, cluster_num = c(3,3), tree_color_rows = c("#008B45FF","#631879FF","#008280FF"), tree_color_cols = c("#1F77B4FF","#FF7F0EFF","#2CA02CFF"), annotation_rows = row_metaData, annotation_cols = col_metaData, annotation_color = col ) p ``` -------------------------------- ### Install ggheatmap from CRAN Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/README.md Use the standard R package installation command to install from CRAN. ```R install.packages("ggheatmap") ``` -------------------------------- ### Install ggheatmap from GitHub Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/README.md Use devtools to install the package directly from the GitHub repository. ```R devtools::install_github("XiaoLuo-boy/ggheatmap") ``` -------------------------------- ### Create and Customize a Heatmap Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/man/ggheatmap.Rd Demonstrates generating a heatmap with row scaling and clustering, followed by theme customization using aplot. ```R #Create data library(ggheatmap) library(tidyr) library(aplot) set.seed(123) df <- matrix(runif(600,0,10),ncol = 12) colnames(df) <- paste("sample",1:12,sep = "") rownames(df) <- sapply(1:50, function(x)paste(sample(LETTERS,3,replace = FALSE),collapse = "")) head(df) #example 1 text_rows <- sample(rownames(df),3) p <- ggheatmap(df,scale = "row",cluster_rows = TRUE,cluster_cols = TRUE, text_show_rows = text_rows)\%>\% ggheatmap_theme(1,theme =list( theme(axis.text.x = element_text(angle = 90,face = "bold"), axis.text.y = element_text(colour = "red",face = "bold")) )) ``` -------------------------------- ### Generate Heatmap with Clustering and Shapes Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/man/ggheatmap.Rd Shows how to create a heatmap with specific cell shapes, cluster counts, and custom tree colors. ```R #example 2 ggheatmap(df,cluster_rows = TRUE,cluster_cols = TRUE, border = "grey", shape = "circle", cluster_num = c(5,4), tree_color_rows = c("#3B4992FF","#EE0000FF","#008B45FF","#631879FF","#008280FF"), tree_color_cols = c("#0073C2FF", "#EFC000FF" ,"#868686FF", "#CD534CFF") ) ``` -------------------------------- ### Generate and style a heatmap with ggheatmap Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/README.md Configures heatmap clustering, annotations, and positions, then applies a custom theme using ggheatmap_theme. ```R ggheatmap(df,cluster_rows = T,cluster_cols = T,scale = "row", text_show_rows = text_rows, border = "grey", cluster_num = c(3,3), tree_color_rows = c("#008B45FF","#631879FF","#008280FF"), tree_color_cols = c("#1F77B4FF","#FF7F0EFF","#2CA02CFF"), annotation_rows = row_metaData, annotation_cols = col_metaData, annotation_color = col, text_position_rows = "left", text_position_cols = "top", tree_position_rows = "right", tree_position_cols = "bottom", annotation_position_rows = "right", annotation_position_cols = "bottom" )%>% ggheatmap_theme(1,theme =list(theme(axis.text.x = element_text(angle = 90,face = "bold",size = 10), axis.text.y = element_text(colour = "red",face = "bold")))) ``` -------------------------------- ### Create a complex heatmap with annotations and themes Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/man/ggheatmap.Rd Generates a heatmap with row and column metadata, clustering, and custom color schemes, followed by theme adjustments. ```R row_metaData <- data.frame(exprtype=sample(c("Up","Down"),50,replace = TRUE), genetype=sample(c("Metabolism","Immune","None"),50,replace = TRUE)) rownames(row_metaData) <- rownames(df) col_metaData <- data.frame(tissue=sample(c("Normal","Tumor"),12,replace = TRUE), risklevel=sample(c("High","Low"),12,replace = TRUE)) rownames(col_metaData) <- colnames(df) exprcol <- c("#EE0000FF","#008B45FF" ) names(exprcol) <- c("Up","Down") genecol <- c("#EE7E30","#5D9AD3","#D0DFE6FF") names(genecol) <- c("Metabolism","Immune","None") tissuecol <- c("#98D352","#FF7F0E") names(tissuecol) <- c("Normal","Tumor") riskcol <- c("#EEA236FF","#46B8DAFF") names(riskcol) <- c("High","Low") col <- list(exprtype=exprcol,genetype=genecol,tissue=tissuecol,risklevel=riskcol) p<- ggheatmap(df,cluster_rows = TRUE,cluster_cols = TRUE,scale = "row", cluster_num = c(5,3), tree_color_rows = c("#3B4992FF","#EE0000FF","#008B45FF","#631879FF","#008280FF"), tree_color_cols = c("#1F77B4FF","#FF7F0EFF","#2CA02CFF"), annotation_rows = row_metaData, annotation_cols = col_metaData, annotation_color = col ) p ggheatmap_theme(p,2:5,theme = list( theme(legend.text = element_text(face = "bold")), theme(legend.text = element_text(face = "bold")), theme(legend.text = element_text(face = "bold")), theme(legend.text = element_text(face = "bold")) )) ``` -------------------------------- ### ggheatmap_plotlist(ggheatmap) Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/man/ggheatmap_plotlist.Rd Displays the basic elements of a ggheatmap object. ```APIDOC ## ggheatmap_plotlist ### Description Display the basic elements of the ggheatmap. ### Usage `ggheatmap_plotlist(ggheatmap)` ### Arguments - **ggheatmap** (heatmap) - The result object of a ggheatmap call. ### Returns - **plotlist** - A list of plots contained within the ggheatmap object. ``` -------------------------------- ### ggheatmap_theme(ggheatmap, plotlist, theme) Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/man/ggheatmap_theme.Rd Sets the styles of the drawing elements for specific components within a ggheatmap object. ```APIDOC ## ggheatmap_theme ### Description Set the styles of the drawing elements of each component of the ggheatmap except cluster tree. ### Usage ggheatmap_theme(ggheatmap, plotlist, theme) ### Arguments - **ggheatmap** (object) - The result of a ggheatmap call. - **plotlist** (integer) - The plotlist index in ggheatmap. Use ggheatmap_plotlist for reference. - **theme** (list) - The theme settings for the plotlist. See the standard theme documentation for more details. ### Returns - **ggheatmap** (object) - The modified ggheatmap object. ``` -------------------------------- ### ggheatmap(df, ...) Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/man/ggheatmap.Rd Generates a heatmap from a data frame with options for clustering, scaling, and adding annotations. ```APIDOC ## ggheatmap(df, ...) ### Description Creates a heatmap visualization from a provided data frame. Supports row and column clustering, data scaling, and integration with metadata annotations. ### Parameters - **df** (data.frame) - The input data frame to visualize. - **cluster_rows** (boolean) - Whether to perform hierarchical clustering on rows. - **cluster_cols** (boolean) - Whether to perform hierarchical clustering on columns. - **scale** (string) - Scaling method for the data (e.g., "row"). - **cluster_num** (vector) - Number of clusters for rows and columns. - **tree_color_rows** (vector) - Colors for row dendrogram branches. - **tree_color_cols** (vector) - Colors for column dendrogram branches. - **annotation_rows** (data.frame) - Metadata for row annotations. - **annotation_cols** (data.frame) - Metadata for column annotations. - **annotation_color** (list) - Color mapping for annotations. - **annotation_position_rows** (string) - Position of row annotations (e.g., "right"). ``` -------------------------------- ### ggheatmap(data, ...) Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/man/ggheatmap.Rd Generates a heatmap visualization based on the provided matrix or data frame, with options for clustering, scaling, and annotation. ```APIDOC ## Function: ggheatmap ### Description Creates a heatmap using the ggplot2 system. It allows for flexible label settings, clustering tree visualization, and integration with other ggplot2 objects. ### Parameters - **data** (matrix/data.frame) - Required - Input data for the heatmap. - **color** (vector) - Optional - Color palette for the heatmap. - **legendName** (character) - Optional - Title of the heatmap legend. - **scale** (character) - Optional - Scaling method: "none", "row", or "column". - **shape** (character) - Optional - Cell shape: "square", "circle", or "triangle". - **cluster_rows** (boolean) - Optional - Whether to cluster rows. - **cluster_cols** (boolean) - Optional - Whether to cluster columns. - **dist_method** (character) - Optional - Distance method for clustering (see dist). - **hclust_method** (character) - Optional - Clustering method (see hclust). - **annotation_cols** (data.frame) - Optional - Column annotations. - **annotation_rows** (data.frame) - Optional - Row annotations. - **annotation_color** (list) - Optional - Colors for annotations. ### Returns - **p** (ggplot object) - The resulting heatmap object. ``` -------------------------------- ### Customize heatmap annotation position Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/man/ggheatmap.Rd Demonstrates how to specify the position of row annotations in the heatmap. ```R ggheatmap(df,cluster_rows = TRUE,cluster_cols = TRUE,scale = "row", cluster_num = c(5,3), tree_color_rows = c("#3B4992FF","#EE0000FF","#008B45FF","#631879FF","#008280FF"), tree_color_cols = c("#1F77B4FF","#FF7F0EFF","#2CA02CFF"), annotation_rows = row_metaData, annotation_cols = col_metaData, annotation_color = col, annotation_position_rows="right" ) ``` -------------------------------- ### ggheatmap() Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/README.md The primary function to draw a heatmap with various customization options for data scaling, clustering, and annotations. ```APIDOC ## ggheatmap(data, ...) ### Description Draws a heatmap based on the provided input data. ### Parameters - **data** (matrix or data.frame) - Required - Input data - **color** (character) - Optional - The color of the heatmap - **legendName** (character) - Optional - The title of the heatmap legend - **scale** (character) - Optional - The way of scale data ("none", "row" or "column") - **border** (character) - Optional - The colour of the border - **shape** (character) - Optional - The shape of cell ("square", "circle" and "triangle") - **cluster_rows** (boolean) - Optional - Whether rows should be clustered - **cluster_cols** (boolean) - Optional - Whether column should be clustered - **dist_method** (character) - Optional - The method parameter of dist function - **hclust_method** (character) - Optional - The method parameter of hclust function - **text_show_rows** (character) - Optional - Labels to show for y-axis - **text_show_cols** (character) - Optional - Labels to show for x-axis - **text_position_rows** (character) - Optional - Position of y-axis label ("right" or "left") - **text_position_cols** (character) - Optional - Position of x-axis label ("bottom" or "top") - **annotation_cols** (data.frame) - Optional - Data for column annotation - **annotation_rows** (data.frame) - Optional - Data for row annotation - **annotation_color** (list) - Optional - Colors for annotation - **annotation_width** (numeric) - Optional - Width for annotation - **annotation_position_rows** (character) - Optional - Position of column annotation ("right" or "left") - **annotation_position_cols** (character) - Optional - Position of row annotation ("bottom" or "top") - **show_cluster_cols** (boolean) - Optional - Whether to show column cluster tree - **show_cluster_rows** (boolean) - Optional - Whether to show row cluster tree - **cluster_num** (numeric) - Optional - Number for cutting cluster tree - **tree_height_rows** (numeric) - Optional - Row cluster tree height - **tree_height_cols** (numeric) - Optional - Column cluster tree height - **tree_color_rows** (character) - Optional - Color for row cluster tree - **tree_color_cols** (character) - Optional - Color for column cluster tree - **tree_position_rows** (character) - Optional - Position of row cluster tree ("right" or "left") - **tree_position_cols** (character) - Optional - Position of column cluster tree ("bottom" or "top") - **levels_rows** (character) - Optional - Levels for y-axis label - **levels_cols** (character) - Optional - Levels for x-axis label ``` -------------------------------- ### Display Heatmap Elements Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/README.md Extract and display the individual components of the generated heatmap object. ```R ggheatmap_plotlist(p) ``` -------------------------------- ### Append ggplot2 objects to heatmap Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/man/ggheatmap.Rd Shows how to insert an additional ggplot2 visualization to the side of the heatmap. ```R dat <- data.frame(marker=sample(c(1,NA),50,replace = TRUE), gene=rownames(df), shape=sample(c("T","F"),50,replace = TRUE)) p1 <- ggplot(dat,aes(x=1,y=gene,size=marker,color=shape,shape=shape))+ geom_point()+theme_classic()+ scale_color_manual(values = c("#D2691E","#1E87D2"))+ theme(line = element_blank(),axis.text = element_blank(),axis.title = element_blank())+ guides(size = FALSE) p%>%insert_right(p1,width = 0.1) ``` -------------------------------- ### ggheatmap_theme(p, indices, theme) Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/man/ggheatmap.Rd Applies custom ggplot2 themes to specific components of a ggheatmap object. ```APIDOC ## ggheatmap_theme(p, indices, theme) ### Description Modifies the theme of specific elements within a generated ggheatmap object. ### Parameters - **p** (object) - The ggheatmap object. - **indices** (vector) - Numeric indices of the heatmap components to modify. - **theme** (list) - A list of ggplot2 theme objects to apply. ``` -------------------------------- ### Customize Heatmap Theme Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/README.md Apply ggplot2 themes to specific elements of the heatmap using the pipe operator. ```R p%>% ggheatmap_theme(1:5, theme =list( theme(axis.text.x = element_text(angle = 90,face = "bold",size = 10), axis.text.y = element_text(colour = "red",face = "bold")), theme(legend.title = element_text(face = "bold")), theme(legend.title = element_text(face = "bold")), theme(legend.title = element_text(face = "bold")), theme(legend.title = element_text(face = "bold")) )) ``` -------------------------------- ### Set Heatmap Border Color Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/README.md Define the border color for heatmap cells during the initial function call. ```R ggheatmap(df,cluster_rows = T,cluster_cols = T,scale = "row", text_show_rows = text_rows, border = "grey", cluster_num = c(3,3), tree_color_rows = c("#008B45FF","#631879FF","#008280FF"), tree_color_cols = c("#1F77B4FF","#FF7F0EFF","#2CA02CFF"), annotation_rows = row_metaData, annotation_cols = col_metaData, annotation_color = col )%> ggheatmap_theme(1,theme =list(theme(axis.text.x = element_text(angle = 90,face = "bold",size = 10), axis.text.y = element_text(colour = "red",face = "bold")))) ``` -------------------------------- ### Change Heatmap Cell Shape Source: https://github.com/xiaoluo-boy/ggheatmap/blob/main/README.md Modify the visual representation of heatmap cells by setting the shape parameter to 'circle'. ```R ggheatmap(df,cluster_rows = T,cluster_cols = T,scale = "row", text_show_rows = text_rows, border = "grey", shape = "circle", cluster_num = c(3,3), tree_color_rows = c("#008B45FF","#631879FF","#008280FF"), tree_color_cols = c("#1F77B4FF","#FF7F0EFF","#2CA02CFF"), annotation_rows = row_metaData, annotation_cols = col_metaData, annotation_color = col )%> ggheatmap_theme(1,theme =list(theme(axis.text.x = element_text(angle = 90,face = "bold",size = 10), axis.text.y = element_text(colour = "red",face = "bold")))) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.