如何在 ggraph / ggplot2 中按顺序设置辅助 x 轴?

问题描述

我想我已经失去了处理这个错误的周末我决定发布我的代码 头疼。

我有这个矩阵

library(tidyverse)
library(tidygraph)
library(ggraph)
library(scales)

mat <- matrix(c(10,10,2,5,1,9,6,7,3,1),nrow=11,ncol=7,byrow = TRUE)
colnames(mat) <- c(0,12,40,50,60,70,90)

rownames(mat) <- c(12,20,30,80,90,100,120)

然后我用 ggraph 将它绘制为二部网络,然后我取了一个完全扭曲/疯狂的 x 轴。

(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())

为什么我的 x 轴不能从 0 开始?

enter image description here

我想在底部的 x 轴上看到以下顺序, 0,90 而不是 90,70 我非常感谢您对这个主题的任何帮助。

脚注:非常感谢 Martin Gal 的评论

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)