circlize
circlize copied to clipboard
How do we control the distance between text labels and the circle
Hi, Jokergoo
Great to have found this wonderful R library and the chord diagram it makes is really amazing.
But, I don't know how to control the distance between the text label and the circle, i.e., the ring. It looks like the longer the text label, the further they are away from the circle. Below are my codes and the product.
I am looking forward to your reply and I know there is much to learn about this wonderful tool. Many thanks.
Regards,
Tom
library(circlize)
Input matrix
values <- c( 1,0,0,2,0, 1,0,1,1,0, 1,0,0,0,0, 1,0,0,0,0, 4,0,3,4,0, 7,2,4,10,0, 2,0,0,0,0, 1,0,1,1,1, 1,0,0,0,0, 7,0,10,15,0, 0,0,0,1,0, 1,0,0,0,0, 1,0,0,1,0, 4,0,1,6,0, 4,0,0,4,0, 1,0,0,1,0, 1,0,0,2,0, 0,0,0,1,0, 1,0,0,2,0, 11,1,36,33,6 ) matrix <- matrix(values, 5, 20)
Labeling
rownames(matrix) <- c("Age 65 to 80", "Over 80", "Age 30 to 50", "Age 50 to 65", "Less than 30") # Label the row categories colnames(matrix) <- c("Diabetes", "DM, HTN", "DM, HTN, HF", "DM, Stroke, HTN", "Heart failure", "Hyptension", "HTN, HF", "Stroke", "Stroke, HTN", "Atrial fibrillation", "AF, DM", "AF, DM, HF", "AF, DM, HTN, HF", "AF, HF", "AF, HTN", "AF, HTN, HF", "AF, Stroke", "AF, Stroke, HF", "AF, Stroke, HTN", "No comorbidity") # Label the column categories
Define colors
colors <- c("Over 80" = "Red", "Age 50 to 65" = "#008000", "Age 30 to 50" = "Orange", "Age 65 to 80" = "#ffef00", "Less 30" = "#2a52be", "No comorbidity" = "black", "AF" = "#ff0800", "Diabetes" = "#a52a2a", "HTN" = "#ffbcd9")
Generate the chord diagram
chordDiagram(matrix, transparency = 0.6, annotationTrack = c("axis", "grid")) ### Make the chord diagram
circos.par(canvas.xlim = c(-0.80, 0.80), canvas.ylim = c(-0.80, 0.80)) chordDiagram(matrix, grid.col = colors, scale = FALSE, annotationTrack = c("grid", "axis"), preAllocateTracks = list(track.height = max(strwidth(unlist(dimnames(matrix)))))) circos.track(track.index = 1, panel.fun = function(x, y) { circos.text(CELL_META$xcenter, CELL_META$ylim[1], CELL_META$sector.index, facing = "clockwise", niceFacing = TRUE, adj = c(-0.30, 0), cex = 0.50) }, bg.border = NA) # here set bg.border to NA is important title(main = "Figure 1 Relationship between age categories and comorbidities", font.main = 1)