I think I have lost my weekend dealing with this error for this I decided to post my code headache.
I have this matrix
library(tidyverse)
library(tidygraph)
library(ggraph)
library(scales)
mat <- matrix(c(10,10,0,2,5,0,1,
10,9,1,2,6,0,1,
10,9,1,1,5,1,1,
10,10,1,2,6,1,1,
10,10,2,6,7,1,1,
10,9,7,6,7,3,2,
10,10,2,6,7,1,1,
10,7,2,5,7,1,1,
10,10,2,5,7,1,1,
10,9,2,5,7,1,1,
10,10,2,6,7,1,1), nrow=11, ncol=7, byrow = TRUE)
colnames(mat) <- c(0,12,40,50,60,70,90)
rownames(mat) <- c(12,20,30,40,50,60,70,80,90,100,120)
and I plot it as bipartite network with ggraph and then I am taking a completely distorted/crazy x-axis.
(layout <- create_layout(mat, "bipartite"))
ggraph(layout) +
geom_edge_link0(aes(edge_width = weight),edge_colour = "black", alpha=0.9) +
scale_edge_width(range = c(1, 10)) +
geom_node_point(aes(shape = type, colour = type), size = 10) +
scale_colour_manual(values = c("#02BEC4", "#45BF44")) +
scale_shape_manual(values = c(15, 19)) +
scale_x_continuous(
breaks = layout$x[!layout$type],
labels = layout$name[!layout$type],
position = "top",
sec.axis = dup_axis(
breaks = layout$x[layout$type],
labels = layout$name[layout$type],
)
) +
theme(axis.text = element_text())
Why my x-axis can not start from 0?
I want to see in the x-axis at the bottom the following order, 0,12,40,50,60,70,90 and not 90,12,60,50,0,40,70 I would highly appreciate any help in the topic.
footnote: Many thanks to Martin Gal for his comment