R Markdown
library(circlize)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(RColorBrewer)
df = data.frame(from = c("B", "C", "D", "A", "B"), to = c("A", "B", "C", "B", "D"), value = c(2, 5, 6, 4, 1))
lab <- data.frame(factor = c("A", "B", "C", "D"), label = c("JPMM Home", "Andrew Carroll Gray", "jimbogray", "DSG"))
grid.cols <- brewer.pal(4, "Set1")
names(grid.cols) <- c("A", "B", "C", "D")
circos.clear()
circos.par(start.degree = 90, gap.degree = 3, track.margin = c(-0.1, 0.1),
cell.padding = c(0,0),
points.overflow.warning = FALSE)
par(mar = rep(0, 4), bg = "lightgrey")
chordDiagram(df, directional = 1, link.arr.type = "big.arrow",
transparency = 0.1, link.sort = TRUE, annotationTrack = "grid",
direction.type = c("arrows", "diffHeight"), diffHeight = -0.04,
annotationTrackHeight = c(0.01, 0.01), col = grid.cols[df$from], grid.col = grid.cols,
link.largest.ontop = TRUE,
order = c("A", "B", "C", "D"))
circos.trackPlotRegion(
bg.border = NA,
track.index=1,
panel.fun = function (x,y) {
xlim = get.cell.meta.data("xlim")
sector.index = get.cell.meta.data("sector.index")
theta = mean(get.cell.meta.data("xplot")) %% 360
if(theta < 90 || theta > 270) {
text.facing = "clockwise"
text.adj = c(0, 0.5)
pos = 4
} else {
text.facing = "reverse.clockwise"
text.adj = c(1, 0.5)
pos = 2
}
circos.text(x = mean(xlim), y = 1, labels = lab$label[lab$factor == sector.index],
facing = text.facing, pos = pos, col = "white")
})
