Entering edit mode
16 days ago
Yukta
•
0
I have this R script that helps generate a circular heatmap, but as I'm running it, I keep getting this gap.degree
error. I am not able to understand what this error means. I tried searching for a solution, but I haven't found one that I can understand. Can someone please help me solve this issue? or understand it?
library(circlize)
library(ComplexHeatmap)
library(dendextend)
# Read VST counts
vst_data <- read.csv("ALL/L2FC1/VST_counts_genes_of_interest.csv", row.names = 1)
head(vst_data)
# Convert to matrix and z-score scale by row
vst_matrix <- as.matrix(vst_data)
vst_matrix_scaled <- t(scale(t(vst_matrix))) # z-score normalization
head(vst_matrix_scaled)
Transpose: genes as columns, samples as rows for circular heatmap
mat_t <- t(vst_matrix_scaled)
head(mat_t)
Color gradient function
col_fun <- colorRamp2(c(-3, 0, 3), c("blue", "white", "red"))
na_col <- "grey80" # Color for missing values
# Create dendrogram of genes
dend <- as.dendrogram(hclust(dist(vst_matrix_scaled)))
gene_order <- order.dendrogram(dend)
# Reorder matrix by gene clustering
mat_t <- mat_t[, gene_order]
# Fix: set gap.after based on number of samples (rows in mat_t)
sample_count <- nrow(mat_t)
head(sample_count)
[1] 15
circos.clear()
circos.par(start.degree = 90, gap.after = c(rep(2, sample_count - 1), 10))
# Draw circular heatmap
circos.heatmap(
mat_t,
col = col_fun,
na.col = na_col,
cluster = FALSE,
dend.side = "inside",
dend.track.height = 0.15,
track.height = 0.08,
rownames.side = "outside",
show.sector.labels = TRUE,
heatmap_limits = c(-3, 3)
)
Error: Since gap.degree
parameter has length larger than 1, it should have same length as the number of sectors.
Thank you @Bastien Hervé I tried the same thing in my own way. The 'split' argument i tried using in circos.heatmap function only, it solved the graph.degree error but gave another new error.
Also I didn't want to transpose my data, so I went ahead without transposing it.
here is the script that I used:
but there is new error pop up:
and this is the heatmap generated :
What do you want to do ?
I've referred to this same example of circos.heatmap and generated the code, but what I need is a heatmap where the gene names should be displayed on the outer circle, and the treatments to be shown on one side of the heatmap, defining the different columns for expression.
Like this a reference heatmap that I generated from SR plot :
Let's say this is your original dataframe :
You were trying to use gap.after to leave white space between your genes. But as far as I know it is not possible without modifying
circos.heatmap
code.One way to circonvent this is to split your matrix for each gene. However splitting your matrix that way trigger the clustering method of
circos.heatmap
on each individual split, raising an error message because you are trying to cluster each individual gene. It is still possible to plot it that way turning off the clustering.A second way is to forget about white spaces between genes, then the clustering is based on all your genes and your don't need to split anything.
@Bastien Herve thank you for the help, I understood the gap.degree and the clustering method. The code worked for me with my data also.
Please consider accepting the original answer (green check mark) to provide closure to this thread).