Issue in circular heatmap, the rows value are getting interchanged.
1
3
Entering edit mode
7 weeks ago
Yukta ▴ 30

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. VST df

heatmap generated

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?

R circos heatmap circularheatmap • 663 views
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

The need is a heatmap only, so I cannot opt for another figure. Thank you for responding though ^^

ADD REPLY
0
Entering edit mode
7 weeks ago

Open an issue here

In circos.heatmap vignette, on the first heatmap, you can guess the row R71 in the block "a". With C10/C9 as positive, C3/C4/C5/C6 as negative and C1/C2/C7/C8 around 0.

heatmap1

On section 6.3 on the circlize heatmap, R71 is on the right side of the plot, third to last.

circlize1

Guessing by the colors, one would expect C1/C2 next to the outside border and C9/C10 on the inside.

But in section 6.8 on the circlize heatmap, you can see that the labels are flipped as well.

circlize2

ADD COMMENT
0
Entering edit mode

Yes, that's the issue, the column's information is getting flipped, but not the column headers. In my dataframe , the values of A are on the outside and the values of E are inside but the headers are vice-versa. I have opened an issue on the link you provided. Thank you for responding and giving your insights.

ADD REPLY

Login before adding your answer.

Traffic: 1277 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6