I am trying to figure out how to add attribute data to a tidygraph object specifically for plotting purposes. I can't seem to figure out how take a variable which is associated with a variable level, preserve it when I create a tidygraph object for use later in a plot. So in the reprex below, I'd like to colour by height but the approach escapes me
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
Can anyone recommend any good way to add height
to this plot?
Created on 2019-03-11 by the reprex package (v0.2.1)