扇区之间的重复链接使程序包R

时间:2018-10-19 10:00:56

标签: r data-visualization circlize

我正在尝试使用Circlize Package进行圆形可视化,但是不幸的是,它正在复制扇区之间的链接。这是我的数据集,我要从中查看不同的域是否共享相同的会话ID:

mat <- structure(list(Website = c("domain1", "domain2", "domain3", "domain2", "domain4", 
                                          "domain1", "domain2"), 
                              ClientID = c("xxx", "xxx", "yyy", "yyy", "yyy", "zzz", "zzz"), 
                              SessionId = c("d.0686", "d.0686", "f.1871", "f.1871", "f.1871", 
                                            "n.9210", "n.9210")), 
                         .Names = c("Website", "ClientID", "SessionId"), 
                         row.names = c(NA, -7L), class = "data.frame")


domains <- unique(mat$Website)
output <- matrix(0, length(domains), length(domains))
colnames(output) <- rownames(output) <- domains

for (x in domains) {
  X <- unique(mat[mat$Website == x, 'SessionId'])
  for (y in domains) {
    Y <- unique(mat[mat$Website == y, 'SessionId'])
    output[rownames(output) == x, y] <- length(intersect(X, Y))
  }
}

然后我使用circlize()绘制垫子

chordDiagram(output, annotationTrack = "grid", preAllocateTracks = 1, transparency = 0.5, self.link = 1, symmetric = FALSE)
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, 0.5), cex = 0.5)
}, bg.border = NA) # here set bg.border to NA is important

不幸的是,circlize()包为我提供了重复的链接,如下所示

Plot From mat

我不明白为什么它要复制矩阵中的链接而不是将它们合并在一起。是因为我的数据(矩阵是否适合圆化)还是由于圆化绘图中缺少参数?

0 个答案:

没有答案