Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ggraph中的长格式和宽格式等价物_R_Ggraph - Fatal编程技术网

ggraph中的长格式和宽格式等价物

ggraph中的长格式和宽格式等价物,r,ggraph,R,Ggraph,我试图使图表与此类似: 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

我试图使图表与此类似:

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")

使用
tidygraph
,将边和节点数据保持为长格式,作为
tbl\u graph
类的一部分,然后您可以将颜色添加到
geom\u node\u点
是否有一些示例代码,tidygraph的文档非常稀疏,
iris\u g%%作为\u tbl\u graph%%激活(节点)%%>%(键=性状,值=值,萼片。长度:花瓣。宽度)
不起作用。
library(ggplot2)
iris %>%
  mutate(id = seq_len(nrow(iris))) %>%
  gather(key = Trait, value = Value, Sepal.Length:Petal.Width) %>%
  ggplot(aes(x = id, y = Value, color = Trait)) +
  geom_point()