我已经尝试了一段时间来寻找解决方案。我现在已经成功调整了位置和宽度highlight.sector()
通过调整默认轨道边距和默认轨道高度。
我已经通过指定这样做了track.margin
and track.height
初始化时的参数circos.par()
step.
最终产品如下所示。代码在最后答案。
# calculate gaps by country;
# 1 degree between ports, 10 degree between countries
gaps <- rep(1, nrow(port_coords))
gaps[cumsum(as.numeric(tapply(port_coords$Name_short, port_coords$Country_lb, length)))] <- 10
# edit initialising parameters
circos.par(canvas.ylim=c(-1.5,1.5), # edit canvas size
gap.after = gaps, # adjust gaps between regions
track.margin = c(0.01, 0.05), # adjust bottom and top margin
# track.margin = c(0.01, 0.1)
track.height = 0.05)
# Plot chord diagram
chordDiagram(m,
# manual order of sectors
order = port_coords$Name_short,
# plot only grid (no labels, no axis)
annotationTrack = "grid",
# annotationTrack = NULL,
preAllocateTracks = 1,
# adjust grid width and spacing
annotationTrackHeight = c(0.03, 0.01),
# add directionality
directional=1,
direction.type = c("diffHeight", "arrows"),
link.arr.type = "big.arrow",
# adjust the starting end of the link
diffHeight = -uh(1, "mm"),
# adjust height of all links
h.ratio = 0.8,
# add link border
link.lwd = 1, link.lty = 1, link.border="gray35"
# track.margin = c(0.01, 0.1)
)
# Scotland
highlight.sector(port_coords$Name_short[which(port_coords$Country_lb == "Scotland")],
track.index = 1, col = "blue2",
text = "Scotland", cex = 1, text.col = "white",
niceFacing = TRUE, font=2)
# England
highlight.sector(port_coords$Name_short[which(port_coords$Country_lb == "England")],
track.index = 1, col = "red2",
text = "England", cex = 1, text.col = "white",
niceFacing = TRUE, font=2)
# Wales
highlight.sector(port_coords$Name_short[which(port_coords$Country_lb == "Wales")],
track.index = 1, col = "springgreen4",
text = "Wales", cex = 1, text.col = "white",
niceFacing = TRUE, font=2)
# Isle of Man
highlight.sector(port_coords$Name_short[which(port_coords$Country_lb == "Isle of Man")],
track.index = 1, col = "orangered4",
text = "Isle of Man", cex = 1, text.col = "white",
niceFacing = TRUE, font=2)
# Rep. Ireland
highlight.sector(port_coords$Name_short[which(port_coords$Country_lb == "Rep. Ireland")],
track.index = 1, col = "darkorange3",
text = "Ireland", cex = 1, text.col = "white",
niceFacing = TRUE, font=2)
# N.Ireland
highlight.sector(port_coords$Name_short[which(port_coords$Country_lb == "N.Ireland")],
track.index = 1, col = "magenta4",
text = "NI", cex = 1, text.col = "white",
niceFacing = TRUE, font=2)
# add labels and axis manually
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")
# print labels & text size (cex)
# circos.text(mean(xlim), ylim[1] + .7, sector.name,
# facing = "clockwise", niceFacing = TRUE, adj = c(0, 0.5), cex=0.6)
circos.text(mean(xlim), ylim[1] + 2, sector.name,
facing = "clockwise", niceFacing = TRUE, adj = c(0, 0.5), cex=0.6)
# print axis
circos.axis(h = "bottom", labels.cex = 0.5,
# major.tick.percentage = 0.05,
major.tick.length = 0.6,
sector.index = sector.name, track.index = 2)
}, bg.border = NA)
# re-set circos parameters
circos.clear()