I need to visualize additional information on my chordDiagram made via circlize. I cannot figure out how to. I tried highlight.section
, but that did not seem to work as straightforward
Let's use this data.
set.seed(1)
df <- data.frame(
Genes = 1:52,
Description = sample(LETTERS[1:7], size = 52, replace = TRUE),
value1 = sample(0:1, size = 52, replace = TRUE),
value2 = sample(runif(52, min = 0, max = 0.001), size = 52, replace = TRUE),
value3 = sample(10:20, size = 52, replace = TRUE)
)
I have made this plot using the code below
library(circlize)
library(viridis)
matrix <- with(df, table(Description, Genes))
circos.clear()
circos.par(start.degree = 90)
description_colors <- setNames(viridis(length(rownames(matrix))), rownames(matrix))
col_names_color <- setNames(rep("grey", length(colnames(matrix))), colnames(matrix))
all_colors <- c(description_colors, col_names_color)
# Generate the chord diagram with specified colors
chordDiagram(matrix, transparency = 0.5,
annotationTrack = "grid",
annotationTrackHeight = c(0.03),
preAllocateTracks = list(track.height = 0.1), # Reduced track height for genes
grid.col = all_colors, # Apply colors to both descriptions and genes
directional = -1,
big.gap = 30, small.gap = 1) # Adjust the highlight sector height here
# Text labels for the sectors
circos.trackPlotRegion(track.index = 1, panel.fun = function(x, y) {
xlim = get.cell.meta.data("xlim")
ylim = get.cell.meta.data("ylim")
sector.name = get.cell.meta.data("sector.index")
circos.text(CELL_META$xcenter, ylim[1] + cm_h(2), sector.name,
facing = "clockwise", niceFacing = TRUE, adj = c(0, 0.5))
}, bg.border = NA)
Question
As you can see, df also have $value1, $value2, $value3
.
I want to add something like this:
The df$value
could denote log2-fold change
or FDR
. Therefore, a gradient color legend should be added and correspond to each of the 3 values.
OBS: The df$value3
has been drawn "below" / on the inside of the "directional" color. It may also be drawn on the "outside" of the grey colored areas of each df$Gene so the directional color maintain a clear connection to each Description.