如何在R的geom_link2中的链接上添加边线/边线? [英] How to add edges/borders to the links in geom_link2 in R?

查看:127
本文介绍了如何在R的geom_link2中的链接上添加边线/边线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在使用R中的 ggforce :: geom_link2 创建的链接中添加边缘/边界(不确定正确的单词)?类似于pch> 20的点.

我看到的问题是geom_link2使用 col 而不是 fill 来定义链接的颜色.因此,我不确定如何定义边框的颜色.反过来,这使我认为无法在链接上形成边框.
有什么主意吗?
谢谢.

编辑10/02/21:来自@tjebo的解决方案.

这里是跨越路径问题的可复制示例.边界在十字路口消失.有了2条路径,仍然可以可视化,但是在复杂的排序中,它会变得非常混乱.

 库(ggforce)#>正在加载所需的软件包:ggplot2df <-data.frame(x = c(5,10,5,10),y = c(5,10,10,5),宽度= c(1,10,6,2),颜色=字母[1:4],组= c(1,1,2,2))ggplot(df)+geom_path(aes(x = x,y = y,group = group),size = 10,lineend ='round')+geom_link2(aes(x = x,y = y,color = colour,group = group),size = 5,lineend ='round',n = 500) 

由(v0.3.0)创建于2021-02-06 sup>

Is there a way to add an edge/border (not sure of the proper word) to the links created using ggforce::geom_link2 in R? Something similar to points with pch >20.

The issue that I see is that geom_link2 uses col instead of fill in order to define the colour of the link. Therefore I am not sure how the colour of the border could be defined. In turn that makes me think that there is no way to make a border on the link.
Any idea?
Thanks.

EDIT 10/02/21: follow up of the solution from @tjebo.

Here is a reproducible example of the path-crossing issue. The border disappears at the crossing. With 2 paths it is still ok to visualise, but in a complex ordination it gets very messy.

library(ggforce)
#> Loading required package: ggplot2
df <- data.frame( x = c(5, 10, 5, 10), y = c(5, 10, 10, 5), width = c(1, 10, 6, 2), colour = letters[1:4], group = c(1, 1, 2, 2))
ggplot(df) +
  geom_path(aes(x = x, y = y,  group = group), size = 10, lineend = 'round') +
  geom_link2(aes(x = x, y = y, colour = colour, group = group), 
             size = 5, lineend = 'round', n = 500) 

Created on 2021-02-10 by the reprex package (v1.0.0)

解决方案

Cheeky workaround: Create two geom_link2 plots overlaid. If you want a simple unicolor border, you can as well (and better) use geom_path instead.

Adapted from the example in ?geom_link.

library(tidyverse)
library(ggforce)
lines <- data.frame( x = c(5, 12, 15, 9, 6), y = c(17, 20, 4, 15, 5), xend = c(19, 17, 2, 9, 5), yend = c(10, 18, 7, 12, 1), width = c(1, 10, 6, 2, 3), colour = letters[1:5])

ggplot(lines) +
  geom_path(aes(x = x, y = y,  group = 1), size = 10, lineend = 'round') +
  geom_link2(aes(x = x, y = y, colour = colour, group = 1), 
             size = 5, lineend = 'round', n = 500) 

Created on 2021-02-06 by the reprex package (v0.3.0)

这篇关于如何在R的geom_link2中的链接上添加边线/边线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆