具有突出显示、无向和有限边缘的和弦图 (R)
我想展示某些项目(A01,...,Q04)及其协作(边缘)的网络。应该可以突出显示从一个项目到其他项目的所有边缘(黄色)。 这是目前的结果。
我有三个问题,我需要帮助解决:
- 我的边缘列表被认为是有向的,但我希望它是无向的。所有项目只应在圆圈中显示一次。
- 项目的顺序应为“A01,...,A09,B01,...B07,Q01,...Q04”,如
crc_color_circlize
所示。 - 来自一个顶点的边数应始终为“一”。现在,我在“B06”和其他项目之间有很多边缘,但这些应该“合并”到“B06”之外的一个边缘中。换句话说,所有项目顶点都具有相同的宽度。
这是我的代码:
library(circlize)
crc_edges <- read.table(header=TRUE,
sep=",",
text="from,to
A01,A02
A01,B06
A02,A03
A02,B05
A02,B06
B06,A01
B06,A07
B06,Q01
B06,Q02
B06,B02
B06,B03
B06,B04
B06,A05
B06,A09
B06,B01
A03,A01
A05,A04
A04,B01
A06,Q02
A07,Q04")
crc_edges
crc_color_circlize <- c(
A01 = "#e30066",
A02 = "#e30066",
A03 = "#e30066",
A04 = "#e30066",
A05 = "#e30066",
A06 = "#e30066",
A07 = "#e30066",
A08 = "#e30066",
A09 = "#e30066",
B01 = "#00549f",
B02 = "#00549f",
B03 = "#00549f",
B04 = "#00549f",
B05 = "#00549f",
B06 = "#00549f",
B07 = "#00549f",
Q01 = "#57ab27",
Q02 = "#57ab27",
Q03 = "#57ab27",
Q04 = "#57ab27")
crc_circlize_group <- function(crc_name) {
crc_circlize_local <- function(crc_name){
set.seed(123)
chordDiagram(crc_edges,
row.col = crc_color_circlize,
grid.col = crc_color_circlize,
col = with(crc_edges,
ifelse(from %in% crc_name, "#ffed00",
ifelse(to == crc_name, "#ffed00",
"#ECEDED"))),
transparency = 0.5,
annotationTrack = c("grid"),
preAllocateTracks = list(track.height = max(strwidth(unlist(dimnames(crc_edges))))))
# we go back to the first track and customize sector labels
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))
}, bg.border = NA,
) # here set bg.border to NA is important
circos.clear()
}
crc_circlize_local(crc_name)
}
# hightlight no edge
crc_circlize_group("")
# highlight edges for one vertex
crc_circlize_group("B06")
I would like to display a network of certain projects (A01,...,Q04) and their collaborations (edges). It should be possible to highlight all the edges from one projects to the others (in yellow).
This is the current result.
I have three problems, I need help to solve:
- my edge list is considered as directed, but I want it to be undirected. All projects should be shown just once in the circle.
- The order of the projects should be "A01,...,A09,B01,...B07,Q01,...Q04", as shown in
crc_color_circlize
. - The amount of edges from one vertex should always be "one". Right now I have many edges between "B06" and other projects, but those should be 'merged' into one edge going out of "B06". In other words all project-vertices have the same width.
This is my code:
library(circlize)
crc_edges <- read.table(header=TRUE,
sep=",",
text="from,to
A01,A02
A01,B06
A02,A03
A02,B05
A02,B06
B06,A01
B06,A07
B06,Q01
B06,Q02
B06,B02
B06,B03
B06,B04
B06,A05
B06,A09
B06,B01
A03,A01
A05,A04
A04,B01
A06,Q02
A07,Q04")
crc_edges
crc_color_circlize <- c(
A01 = "#e30066",
A02 = "#e30066",
A03 = "#e30066",
A04 = "#e30066",
A05 = "#e30066",
A06 = "#e30066",
A07 = "#e30066",
A08 = "#e30066",
A09 = "#e30066",
B01 = "#00549f",
B02 = "#00549f",
B03 = "#00549f",
B04 = "#00549f",
B05 = "#00549f",
B06 = "#00549f",
B07 = "#00549f",
Q01 = "#57ab27",
Q02 = "#57ab27",
Q03 = "#57ab27",
Q04 = "#57ab27")
crc_circlize_group <- function(crc_name) {
crc_circlize_local <- function(crc_name){
set.seed(123)
chordDiagram(crc_edges,
row.col = crc_color_circlize,
grid.col = crc_color_circlize,
col = with(crc_edges,
ifelse(from %in% crc_name, "#ffed00",
ifelse(to == crc_name, "#ffed00",
"#ECEDED"))),
transparency = 0.5,
annotationTrack = c("grid"),
preAllocateTracks = list(track.height = max(strwidth(unlist(dimnames(crc_edges))))))
# we go back to the first track and customize sector labels
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))
}, bg.border = NA,
) # here set bg.border to NA is important
circos.clear()
}
crc_circlize_local(crc_name)
}
# hightlight no edge
crc_circlize_group("")
# highlight edges for one vertex
crc_circlize_group("B06")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论