我试图弄清楚如何将属性数据添加到tidygraph对象中,专门用于打印目的。我似乎不知道如何获取与变量级别关联的变量,在创建tidygraph对象以供以后在绘图中使用时保留它。因此,在下面的reprex中,我想按高度上色,但我想不出这种方法
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(tidygraph)
#>
#> Attaching package: 'tidygraph'
#> The following object is masked from 'package:stats':
#>
#> filter
library(ggraph)
#> Loading required package: ggplot2
starwars_graph <- starwars %>%
filter(eye_color == "blue") %>% ## trim down the data
select(species, homeworld, height) %>%
na.omit() %>%
as_tbl_graph()
ggraph(starwars_graph, layout = "nicely") +
geom_edge_link() +
geom_node_label(aes(label = name))
ggraph(starwars_graph, layout = "nicely") +
geom_edge_link() +
geom_node_label(aes(label = name, colour = height))
#> Error in FUN(X[[i]], ...): object 'height' not found
height
这个阴谋?
于2019年3月11日由
reprex package