I am trying to draw a flow map using the circlize
library. My code is below and the dataset (i75_from_flow.RData) is here: https://drive.google.com/file/d/0B0hTmthiX5dpbFJFc2hfN1Zqd1k/view
library(reshape)
t1 <- cast(i75_from_flow, ORIGFIPS ~ TERMFIPS)
i75_from_flow2<- data.matrix(subset(t1, select=-c(1)))
rownames(i75_from_flow2) <- t1$ORIGFIPS
colnames(i75_from_flow2) <- colnames(i75_from_flow2)
library(circlize)
circos.par(gap.degree = 8)
chordDiagram(i75_from_flow2, grid.col= length(union(rownames(i75_from_flow2),colnames(i75_from_flow2))), directional = TRUE, annotationTrack = "grid",
preAllocateTracks = list(list(track.height = 0.05),
list(track.height = 0.05)))
circos.trackPlotRegion(track.index = 1, panel.fun = function(x, y) {
xlim = get.cell.meta.data("xlim")
ylim = get.cell.meta.data("ylim")
sector.index = get.cell.meta.data("sector.index")
circos.text(mean(xlim), mean(ylim), sector.index, facing = "inside", niceFacing = TRUE)
}, bg.border = NA)
When I run the above code I get the following error following the chordDiagram and circos.trackPlotRegion lines in the code.
Error in .CELL.DATA[[1]] : subscript out of bounds
My goal is to get an image that shows the matrix cells as flows between the ORIGFIPS and TERMFIPS.
My question is how to fix error in cell data issue. Should the matrix be symmetric for circlize to work properly? It is not always the case in this effort.