For some reason, this symmetrized matrix is plotting with either no data in the lower triangle of the heatmap or just a little as shown in the below figure. I can't figure out why it's happening. Any guesses? I've shared the first 100 rows of the dataset in the example below.
I'm using the following:
library(igraph)
library(dplyr)
library(ggplot2)
library(viridis)
Edgelist = "from to weight
2D16 31C1 3
2D16 3215 4
2D16 3AFD 3
2D16 3CFF 3
2D16 4777 2
2D16 48E2 3
2D16 4BAA 3
2D16 4FBB 3
2D16 5323 1
2D16 5A68 4
2D16 5D78 4
2D16 5D9E 4
2D16 5E0F 1
2D16 6BF3 2
2D16 6DBC 2
2D16 6EFC 2
2D16 6FB0 4
2D16 714B 3
2D16 735B 1
2D16 7E8A 3
2D16 7F77 1
2D16 8761 4
2D16 82D8 3
2D16 8BE7 2
2D16 8D8C 4
2D16 90B1 1
2D16 9116 1
2D16 9264 3
2D16 99CB 3
2D16 9A69 3
2D16 A26F 3
2D16 A975 3
2D16 AC37 2
2D16 B190 3
2D16 B261 2
2D16 B6DE 3
2D16 B7FD 1
2D16 BAB5 4
2D16 BDB5 1
2D16 C044 2
2D16 C1D9 4
2D16 C400 2
2D16 C574 2
3011 3011 3
3011 31C1 3
3011 3215 3
3011 3AFD 3
3011 3CFF 3
3011 4777 2
3011 48E2 3
3011 4BAA 3
3011 4FBB 3
3011 5323 3
3011 55E2 1
3011 5594 2
3011 5A68 3
3011 5D78 3
3011 5D9E 2
3011 6155 1
3011 6BF3 3
3011 6EFC 1
3011 6FB0 3
3011 714B 2
3011 7E8A 3
3011 843C 1
3011 8761 3
3011 82D8 3
3011 8BE7 1
3011 8D8C 3
3011 90B1 2
3011 9116 1
3011 9264 1
3011 99CB 2
3011 9A69 3
3011 A26F 3
3011 A975 3
3011 AC37 3
3011 B190 1
3011 B261 3
3011 B7FD 2
3011 BAB5 3
3011 BDB5 1
3011 C1D9 1
3011 C574 3
31C1 2D16 3
31C1 3011 3
31C1 31C1 15
31C1 3215 15
31C1 3AFD 15
31C1 3CFF 13
31C1 4777 10
31C1 48E2 15
31C1 4BAA 15
31C1 4FBB 14
31C1 5323 9
31C1 55E2 1
31C1 5594 4
31C1 5A68 13
31C1 5D78 12
31C1 5D9E 13"
Data <- read.table(text=Edgelist, header = TRUE)
graph <- graph.data.frame(Data, directed = FALSE)
V(graph)$comm <- membership(optimal.community(graph))
node_list <- get.data.frame(graph, what = "vertices")
edge_list <- get.data.frame(graph, what = "edges") %>%
inner_join(node_list %>% select(name, comm), by = c("from" = "name")) %>%
inner_join(node_list %>% select(name, comm), by = c("to" = "name")) %>%
mutate(group = ifelse(comm.x == comm.y, comm.x, NA) %>% factor())
all_nodes <- sort(node_list$name)
plot_data <- edge_list %>% mutate(
to = factor(to, levels = all_nodes),
from = factor(from, levels = all_nodes))
ggplot(plot_data, aes(x = from, y = to, fill = weight)) +
geom_tile() +
theme_bw() +
scale_x_discrete(drop = FALSE) +
scale_y_discrete(drop = FALSE) +
theme(axis.title.x=element_blank(),
axis.title.y=element_blank(),
axis.text.x = element_text(angle = 270, hjust = 0),
aspect.ratio = 1,
legend.position = "bottom") +
scale_color_viridis(discrete = FALSE, option = "D") +
scale_fill_viridis(discrete = FALSE)