1

有没有办法在 R 中使用创建的链接添加边缘/边框(不确定正确的词)ggforce::geom_link2?类似于 pch >20 的点。

我看到的问题是 geom_link2 使用col而不是fill为了定义链接的颜色。因此我不确定如何定义边框的颜色。反过来,这让我认为没有办法在链接上制作边框。
任何的想法?
谢谢。

编辑 10/02/21:跟进@tjebo 的解决方案。

这是路径交叉问题的可重现示例。边界在过境点消失。使用 2 条路径仍然可以可视化,但在复杂的排序中它会变得非常混乱。

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) 

reprex 包于 2021-02-10 创建(v1.0.0)

4

1 回答 1

1

厚颜无耻的解决方法:创建两个重叠的 geom_link2 图。如果你想要一个简单的单色边框,你也可以(并且更好)使用 geom_path 代替。

改编自 中的示例?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) 

reprex 包(v0.3.0)于 2021-02-06 创建

于 2021-02-05T11:06:26.267 回答