我的目标是在 map 上创建曲线(连接点),在一侧有一个箭头.这些线将是半透明的.似乎实现我的目标的最好方法是使用geom_curve(尽管其他ggplot2解决方案也会很好).

因此,假设我有这样一个玩具情节:

library(tidyverse)
library(ggplot2)
data <- data.frame(x = 4, y = 20, xend = 7, yend = 15)

ggplot(data) + geom_curve(aes(x = x, y = y, xend = xend, yend = yend),
    arrow = arrow(length = unit(0.17, "npc"), type="closed", angle=20),
    colour = "red",
    linewidth = 5,
    angle = 90, 
    alpha=.2,
    lineend = "butt",
    curvature = -0.4,
) 

This creates: enter image description here

我面临的问题是,当我使用带有半透明线的geom_curve时,当我希望它是统一的时,箭头显示出不同级别的透明度.我如何才能防止这种情况发生?

This question is very closely related to: Alpha aesthetic shows arrow's skeleton instead of plain shape - how to prevent it?, except that it uses geom_curve instead of geom_segment. The brilliant answer (https://stackoverflow.com/a/60587296/2049545) defines a new geometry (geom_arrowbar). Would it be possible to modify this to be used for geom_curve? I will also flag another of the answers that points to geom_gene_arrow (https://stackoverflow.com/a/60655018/2049545) - can this be used with curved lines? Or is there some other solution that would work?

推荐答案

要真正正确地做到这一点,需要编写一个新版本的curveGrob和一个全新的geom.

幸运的是,已经有人这么做了.Teunbrand未发布的ggarrow包包括geom_arrow_curve,所以你可以这样做:

remotes::install_github("teunbrand/ggarrow")

library(ggplot2)
library(ggarrow)

data <- data.frame(x = 4, y = 20, xend = 7, yend = 15)

ggplot(data) + 
  geom_arrow_curve(aes(x = x, y = y, xend = xend, yend = yend),
              colour = "red",
              linewidth = 5,
              angle = 90, 
              alpha = 0.2,
              lineend = "butt",
              curvature = -0.5)

enter image description here

R相关问答推荐

使用spatVector裁剪网格数据时出现的问题

R Lubridate:舍入/快照日期时间到一天中最近的任意时间?

R Markdown中的交叉引用表

将复杂的组合列表转换为数据框架

terra nearest()仅为所有`to_id`列返回NA

lightgbm发动机在tidymmodels中的L1正则化""

如何在geom_col中反转条

如何在Chart_Series()中更改轴值的 colored颜色 ?

如何写商,水平线,在一个单元格的表在R

更改STAT_VALLES/STAT_PEAKS中的箭头线宽/大小

基于Key->Value数据帧的基因子集相关性提取

KM估计的差异:SvyKm与带权重的调查

查找所有站点的最小值

删除数据帧中特定行号之间的每第三行和第四行

基于R中的辅助向量中的值有条件地连接向量中的字符串

R中的Desolve:返回的导数数错误

基于R中的引用将向量值替换为数据框列的值

如何修复geom_rect中的层错误?

基于已有ID列创建唯一ID

用逗号拆分字符串,并删除一些字符