I have a network of friendships and I'm trying to plot each ego network that shows only to out nominations of each ego. When I plot the ego network, it includes arrows directed towards ego and edges connecting alters to each other. I'd like to conditionally remove edges not coming from ego. Sample data and code below:
df<-read.table(text="student_id friendid_1 friendid_2 friendid_3 friendid_4
1 3 NA NA NA
2 5 2 3 NA
3 2 4 5 NA
4 1 6 NA 3
5 1 NA 6 2
6 5 NA 2 1
7 8 NA NA NA
8 NA 9 NA NA
9 8 7 NA NA
10 7 9 NA NA
11 19 15 NA 12
12 20 NA 19 11
13 15 19 11 NA
14 16 NA 12 18
15 17 20 17 NA
16 14 19 20 13
17 20 18 13 14
18 13 NA 19 17
19 17 NA 16 11
20 13 17 11 14", header = TRUE) %>%
pivot_longer(.,
cols = friendid_1:friendid_4) %>%
select(student_id, alter = value) %>%
na.omit()
egonet_3 <- graph_from_data_frame(d = df, directed = TRUE) %>%
make_ego_graph(., order = 1, nodes = V(.) %in% c("3"), mode = "out")
as_tbl_graph(egonet_3[[1]]) %>%
create_layout(., layout = 'fr') %>%
ggraph(.) +
geom_edge_link(color = "black", alpha = 0.7,
arrow = arrow(type = "closed",
angle = 25,
length = unit(1.5, 'mm')),
end_cap = circle(2, 'mm'),
width = 0.5, show.legend = FALSE) +
geom_node_point(size = 4) +
geom_node_label(aes(label = name), repel = TRUE) +
theme_graph() +
theme(legend.position = "none")
This code gives me this image:
However, I want to look like this:
Is there a way to conditionally remove edges not coming from ego? I have a number of plots to make, so removing individual edges by hand is not ideal.