I have a vst file for which I am generating a circular heatmap. The heatmap is being generated but in the image the values of "A" is being changed with "E".
Like for example; some of my values in "A" are positive like fat.1, fat.2 etc. but in the heatmap they are depicted as negative.
I am sharing my R script for which I have generated , but I am not sure why the column values are getting interchanged.
R script:
# Load required libraries
library(circlize)
library(ComplexHeatmap)
library(dendextend)
library(grid)
# ------------------- Data Preprocessing -------------------
#read the scaled data
vst_scaled <- read.csv("ALL/L2FC1/VST_scaled_for_heatmap_updated.csv", row.names = 1)
mat_t <- as.matrix(vst_scaled)
# ------------------- Clustering and Ordering -------------------
# Cluster genes (rows) and reorder
dend <- as.dendrogram(hclust(dist(mat_t)))
gene_order <- order.dendrogram(dend)
mat_t <- mat_t[gene_order, ]
# Color mapping function
col_fun <- colorRamp2(c(-3, 0, 3), c("blue", "white", "red"))
# Prepare legends
# Prepare legends with bold, larger fonts
lgd_links <- Legend(
at = c(-3, -1.5, 0, 1.5, 3),
col_fun = col_fun,
title = "z-score",
direction = "horizontal",
title_position = "topleft",
labels_gp = gpar(fontsize = 16, fontface = "bold"),
title_gp = gpar(fontsize = 18, fontface = "bold")
)
lgd_annotation <- Legend(
labels = c("High", "Low"),
title = "Expression",
legend_gp = gpar(fill = c("red", "blue")),
direction = "horizontal",
title_position = "topleft",
labels_gp = gpar(fontsize = 16, fontface = "bold"),
title_gp = gpar(fontsize = 18, fontface = "bold")
)
# Add a custom sample legend for treatments
lgd_samples <- Legend(
labels = c("A = Control", "B = NN-Extract", "C = NN@AuNPs", "D = Au@NPs", "E = Orlistat"),
title = "Treatments",
direction = "horizontal",
title_position = "topleft",
legend_gp = gpar(fill = NA),
labels_gp = gpar(fontsize = 16, fontface = "bold"),
title_gp = gpar(fontsize = 18, fontface = "bold")
)
# Combine all legends vertically
lgd_combined <- packLegend(lgd_links, lgd_annotation, lgd_samples, direction = "vertical")
# Save to high-resolution PNG (600 DPI)
png("Circos_Heatmap_VST_scaled.png", width = 16, height = 10, units = "in", res = 600)
# Set up layout: 75% plot (left), 25% legend (right)
pushViewport(viewport(layout = grid.layout(nrow = 1, ncol = 2, widths = unit(c(3, 1), "null"))))
# Circos heatmap (left)
pushViewport(viewport(layout.pos.col = 1))
circos.clear()
circos.par(start.degree = 0, gap.after = 10)
circos.heatmap(
mat_t,
col = col_fun,
na.col = "grey80",
cluster = TRUE,
dend.side = "none",
rownames.side = "outside",
track.height = 0.5,
rownames.font = 2,
rownames.cex = 1.5,
rownames.col = "black"
)
# Add sample names on outer track
circos.track(track.index = 2, panel.fun = function(x, y) {
cn <- colnames(mat_t)
n <- length(cn)
if (CELL_META$sector.numeric.index == 1) {
circos.text(rep(CELL_META$cell.xlim[2], n) + convert_x(1, "mm"),
1:n - 0.5, cn,
cex = 1.3, adj = c(0.5, 1), facing = "clockwise", font = 2)
}
}, bg.border = NA)
upViewport() # Exit heatmap
# Legend (right)
pushViewport(viewport(layout.pos.col = 2))
draw(lgd_combined, just = "left")
upViewport()
popViewport() # Exit main layout
dev.off()
Can anyone please help in figuring out the issue?
Have you considered alternatives to a heatmap? My first try would be a line plot with labels (fat.1, fatt2., etc) on the x-axis, the value on y-axis and a line for A, B, C, D, E. It may become a very wide plot if you want the labels to be all readable, but maybe you don't need that and it could still be more space-efficient and readable than a heatmap. My issues with heatmaps is that the colour scale makes more difficult to see patterns and make comparisons relative to a regular line or dot plot.
The need is a heatmap only, so I cannot opt for another figure. Thank you for responding though ^^