我正在尝试在igraph中为R创建一个饼图,其中将每个顶点绘制成饼图,并分为两个相等大小的段,每个段的颜色从蓝色到白色再到红色,基于两个列。我可以为每种颜色创建渐变色,但是我很难弄清楚如何将渐变色映射到饼形图中。我所有的示例都是基于离散值而不是连续值来查找彩色饼图段。
编辑:我在此处并入了更多信息,以创建可复制的示例。
library(igraph)
test1 <- structure(list(From.Molecule.s. = c("EIF2AK2", "ELK1", "FOS"),
To.Molecule.s. = c("CHUK", "FOS", "CD14"), Relationship.Type = structure(c(1L,
1L, 2L), .Label = c("activation", "expression", "inhibition",
"phosphorylation", "protein-DNA interactions", "protein-protein interactions",
"protein-RNA interactions", "reaction", "transcription"), class = "factor"),
color = c("Light Coral", "Light Coral", "Goldenrod")), .Names = c("From.Molecule.s.", "To.Molecule.s.", "Relationship.Type", "color"), row.names = c(20L, 23L, 27L), class = "data.frame")
test1_exp <- structure(list(From.Molecule.s. = c("CD14", "CHUK", "ECSIT",
"EIF2AK2", "ELK1", "FOS"), expression.x = c(-0.454, 0.863, -0.326,
0, -0.31, 0), Expr.p.value.x = c(0.198648, 0.003975, 0.164683,
NA, 0.039658, NA), vector_colors.x = structure(c(1L, 11L, 3L,
27L, 5L, 27L), .Label = c("#0000FF", "#2626FF", "#4848FF", "#4D4DFF",
"#4F4FFF", "#5C5CFF", "#9A9AFF", "#F9F9FF", "#FF0000", "#FF1B1D",
"#FF2426", "#FF3C40", "#FF5459", "#FF565B", "#FF585D", "#FF6369",
"#FF7076", "#FF757C", "#FF777E", "#FF7E86", "#FF8992", "#FF9AA3",
"#FF9FA9", "#FFA5AF", "#FFAEB9", "#FFB6C1", "#FFFFFF"), class = "factor"),
expression.y = c(0.271, -0.022, 0.219, 0, 0.126, 0), Expr.p.value.y = c(0.705028,
0.97643, 0.63173, NA, 0.670641, NA), vector_colors.y = structure(c(17L,
15L, 21L, 28L, 23L, 28L), .Label = c("#0000FF", "#4242FF",
"#5A5AFF", "#7676FF", "#7B7BFF", "#9797FF", "#9D9DFF", "#A7A7FF",
"#ACACFF", "#C6C6FF", "#D0D0FF", "#D8D8FF", "#EFEFFF", "#F2F2FF",
"#F4F4FF", "#FF0000", "#FF282A", "#FF2A2C", "#FF3134", "#FF4044",
"#FF4448", "#FF5257", "#FF777E", "#FF8B94", "#FF8F98", "#FFB0BB",
"#FFB6C1", "#FFFFFF"), class = "factor")), .Names = c("From.Molecule.s.",
"expression.x", "Expr.p.value.x", "vector_colors.x", "expression.y",
"Expr.p.value.y", "vector_colors.y"), row.names = c(NA, 6L), class = "data.frame")
TLR <- graph_from_data_frame(test1, directed = T,vertices = test1_exp)
V(TLR)$size=7.5
V(TLR)$label.cex=0.8
V(TLR)$label.dist=0.75
V(TLR)$label.degree = pi/2
V(TLR)$label.color = "black"
TLR_net <- plot(TLR,edge.arrow.size = 0.15,vertex.shape = "pie",vertex.pie.color = c(V(TLR)$vector_colors.x,V(TLR)$vector_colors.y))
测试输出现在如下所示: