我正在尝试制作类似于此的图表:
else if
我想指定library(tidyverse)
library(ggraph)
iris_g <- den_to_igraph(as.dendrogram(hclust(dist(iris[1:4]))))
xy_expand <- function(xy, expand) xy * (1 + expand / 10)
ord <- match(as.numeric(V(iris_g)$label), seq_len(nrow(iris)))
V(iris_g)$Petal.Length <- iris$Petal.Length[ord]
V(iris_g)$Petal.Width <- iris$Petal.Width[ord]
V(iris_g)$Sepal.Length <- iris$Sepal.Length[ord]
V(iris_g)$Sepal.Width <- iris$Sepal.Width[ord]
V(iris_g)$Species <- iris$Species[ord]
ggraph(iris_g, layout = "dendrogram", circular = TRUE) +
geom_edge_diagonal() +
geom_node_point(aes(filter = leaf,
x = xy_expand(x, Sepal.Length),
y = xy_expand(y, Sepal.Length)),
color = "red") +
geom_node_point(aes(filter = leaf,
x = xy_expand(x, Sepal.Width),
y = xy_expand(y, Sepal.Width)),
color = "green") +
geom_node_point(aes(filter = leaf,
x = xy_expand(x, Petal.Length),
y = xy_expand(y, Petal.Length)),
color = "blue") +
geom_node_point(aes(filter = leaf,
x = xy_expand(x, Petal.Width),
y = xy_expand(y, Petal.Width)),
color = "yellow")
,以便着色很好地集成到图的其余部分,但我无法弄清楚aes(color = Trait)
我想在ggraph
中做的事情相当于:
ggplot