Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do we control the distance between text labels and the circle #400

Open
TomHsiung opened this issue Aug 25, 2024 · 2 comments
Open

How do we control the distance between text labels and the circle #400

TomHsiung opened this issue Aug 25, 2024 · 2 comments

Comments

@TomHsiung
Copy link

TomHsiung commented Aug 25, 2024

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)

Rplots.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@TomHsiung and others