I'm trying to manually adjust the position of the nodes along the x axis in geom_edge_arc2()
so they are not evenly spaced. Instead, I'd like the spacing to reflect the yds
variable in my data set.
I presume this is possible based on the answers here, but when I try and run my code (below), it returns an error saying aesthetics must be either length 1 or the same as the data.
For clarity, the yds_labels
variable I have created is to be eventually used for labelling each node while providing the units ("yds"
) with the first value.
When I attempt to set the x and y coordinates in geom_edge_arc2()
I'm presuming 0 needs to be the reference value. Any help will be greatly appreciated. Thanks.
Code:
library(tidyverse)
library(ggraph)
library(igraph)
set.seed(100)
dat <- data.frame(
origin = rep("Origin", 10),
dest = paste("Dest", 1:10),
n = rnorm(10, 15, 5),
yds = round(abs(rnorm(10, 15, 4)), 1)
) %>%
arrange(yds)
gr <- dat %>%
tidygraph::as_tbl_graph() %>%
tidygraph::activate(nodes) %>%
tidygraph::activate(edges)
x <- dat$yds[1]
z <- nrow(dat)
yds_labels <- c(NA, paste(x, "yds"), dat$yds[2:z])
gr <- set_vertex_attr(gr, "yds_labels", value = yds_vert)
ggraph(gr,
layout = "linear") +
geom_edge_arc2(aes(x = c(0, dat$yds),
y = rep(0, length(dat$dest)),
edge_width = n),
lineend = "round",
vjust = -1,
show.legend = FALSE)