如何在R中生成连接的表格状图

问题描述 投票:1回答:1

我想产生一个类似于下面R中的图

enter image description here

什么是最好的方法?我尝试了DiagrammeR,但没有成功。

任何帮助将不胜感激!!

r diagram
1个回答
0
投票

这可以是您的起点。可以进一步改善。

library(tidyverse)
set.seed(123)
items <- paste0('item',c(1:6))
df <- cbind.data.frame(items = c(sample(items,6),sample(items,6),sample(items,6)), x = rep((1:3),each = 6), y = rep(1:6, 3))

ggplot(df,aes(x = x, y = y)) + 
  geom_line(aes(group = items), size = 1) + 
  geom_tile(width = 0.6, height = 0.6, fill = 'white', color = 'black') + 
  theme_void() + geom_text(aes(label = items))

产生:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.