This is the data I'm using also I'm attaching the sample figure down below.
df <- data.frame(
"PersonName1" = c("F","H","H","H","K","K","K","K","N","N","G","N","N","N","K","G","K"),
"PersonName2" = c("G","G", "F","N","N","F","H","G","G","F","H","F","H","F","F","F","H"),
"P" = c(0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0, 0,0.5,0,0.5,0.5,0.5,0.5),
"Country" = c("UK","UK","UK","UK","UK","UK","UK","UK","UK","UK","UK","Rwanda","Rwanda","Vietnam","Vietnam","Vietnam","Vietnam"))
This is the code I'm using it generates only one figure also I'm using a customised legend as well. I want to get a plot like this. Is there any function in ggraph inorder to implement this?
install.packages('ragg')
install.packages('ggraph')
library(ggraph)
library(tidygraph)
install.packages("cowplot")
library(cowplot)
library(gridExtra)
df <- data.frame(
"PersonName1" = c("No Speaker","No Speaker"),
"PersonName2" = c("Fauci","Hanks"),
"P" = c(0.5, 0) )
df %>%
as_tbl_graph() %>%
activate(edges) %>%
tidygraph::filter(P > 0) %>%
activate(nodes) %>%
ggraph(layout = 'circle') +
geom_node_text(aes(label = name), size = 8,
nudge_x = c(0.2, 0, -0.2, -0.2, 0),
nudge_y = c(0.3, 0.3, 0.3, -0.3, -0.3),
check_overlap = TRUE) +
geom_edge_link2(aes(width = after_stat(index)), color = "red",
alpha = 0.5) +
geom_node_point(size = 20) +
scale_edge_width(range = c(0, 15), guide = 'none') +
coord_cartesian(xlim = c(-1.5, 1.5), ylim = c(-1.5, 1.5)) +
theme_void() ->p_gp
### legend
data.frame(lg1 = "Y", lg2 = "X" , P = 0.5) %>%
as_tbl_graph() %>%
activate(edges) %>%
tidygraph::filter(P > 0) %>%
activate(nodes) %>%
ggraph(layout = 'circle') +
geom_node_text(aes(label = name), size = 4,
nudge_y = c(-0.15, -0.15, -0.15, -0.15, -0.15)) +
geom_edge_link2(aes(width = after_stat(index)), color = "grey",
alpha = 0.5) +
geom_node_point(size = 10) +
scale_edge_width(range = c(0, 5), guide = 'none') +
coord_cartesian(xlim = c(-1.5, 1.5), ylim = c(-1.5, 1.5)) +
theme_void() -> p_lg
ggdraw(p_lg) +
draw_label("Significance", y = 0.66, size = 14) +
draw_label("X significantly", y = 0.62, size = 10) +
draw_label("exceeds Y", y = 0.58, size = 10) +
draw_label("(p < 0.05)", y = 0.54, size = 10) -> p_lg
### grid
grid.arrange(p_gp, p_lg,
ncol=2, nrow=1, widths=c(9/10,1/10))