Rohan Nath
Rohan Nath

Reputation: 105

Circular Heatmap in R: Splitting by values, adding labels in each cell, and handling unequal axes

I am trying to create a circular heatmap in R using the ComplexHeatmap and circlize packages. My dataset is contained in a CSV file named "inter_tm_count.csv", which can be accessed via the Google Drive link provided below:

Google Drive link to the CSV dataset

Here's a summary of my dataset:

  1. Columns: number, characteristic, tm, structure, label, phyla
  2. Rows: Contain information about the number of characteristics (characteristic) occurrences at different transmembrane (TM) locations, categorized by phyla. I'm facing several challenges in creating the heatmap:

Here's my desired output:

  1. Splitting by Phyla: How can I split the heatmap by the phyla column? Since the number of unique tm and characteristic values varies for each phyla, resulting in different dimensions, how can I ensure that the circular heatmap reflects this variability?
  2. Label Placement: I aim to display the label value inside each heatmap cell. Additionally, I'd like to label each phyla outside its corresponding heatmap plot. How can I achieve this label placement?
  3. Color Assignment: I have predefined colors for each characteristic and want to assign these colors to the heatmap cells. Is there a way to accomplish this effectively? Legends: Is it possible to generate unique color gradients for each phyla and display them in the heatmap legend?

Here's my current script:

library(ComplexHeatmap)
library(reshape2)
library(circlize)

# Read the data
inter_tm_count <- read.csv("path/to/inter_tm_count.csv")

# Split the data by the 'phyla' column
split_data <- split(inter_tm_count, inter_tm_count$phyla)

# Assign colors to characteristics
colors <- c("#ffffff", "#f7f9cb", "#c7edc0", "#92e0c3", "#56d0d0", "#00bdde", 
            "#00afef", "#539df4", "#9085e8", "#cd6ace", "#f54a9d", "#ff3d5e", 
            "#f0550d", "#fc8d59")

# Get unique characteristics
characteristics <- unique(inter_tm_count$characteristic)

# Create a named vector of colors
col_vector <- setNames(colors[1:length(characteristics)], characteristics)

# Convert data to matrix format
matrix_data <- acast(inter_tm_count, characteristic ~ tm, value.var = "number")

# Plot heatmap with named vector of colors and cell borders
circos.heatmap(matrix_data, split = split, col = col_vector)
circos.clear()

However, this script doesn't produce the desired plot. How can I modify it to address the challenges above and create the circular heatmap as described?

Any help or guidance would be greatly appreciated. Thank you!

Upvotes: 0

Views: 81

Answers (0)

Related Questions