r - 由 R 图的小箭头组成的线

标签 r plot

这个问题在这里已经有了答案:





R: how do I draw a line with multiple arrows in it?

(5 个回答)


去年关闭。




我想为 R 中的图形定义自定义线型。

作为最小的工作示例,请考虑以下内容

plot(1:5,runif(5),type="l",lty="longdash")

这给了我一些随机线(如下图中的黑色虚线)。有没有办法让破折号看起来像小箭头(就像我用 illustrator 构建的红色例子)?

enter image description here

最佳答案

我继续@cardinal40 的工作。附加值是在我的解决方案中,连续箭头之间有空间。

df2 %>% 
  left_join(df, by = "x") %>% 
  mutate(
    y = if_else(is.na(y), approx(x, y, x)$y, y),

    ## calculate the change in x and y, and take 20%
    x_delta = abs(x-lead(x))*.2,
    y_delta = abs(y -lead(y))*.2,

    ### provide the relative space calculate above but ... 
    ### treat differently depending on descending or ascending
    xend = ifelse(x > lead(x), lead(x)+x_delta, lead(x)-x_delta),
    yend = ifelse(y > lead(y), lead(y)+y_delta, lead(y)-y_delta)

  ) %>% 
  filter(!is.na(xend)) %>% 
  ggplot(aes(x = x, y = y, xend = xend, yend = yend)) +
  geom_segment(arrow = arrow(length = unit(0.1, "inches")))

这产生了以下图表:

enter image description here

关于r - 由 R 图的小箭头组成的线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60456634/

相关文章:

r - 如何避免 R 树形图上的文本以及组数限制

r - 带有 qmplot 的 map 中的点

r - 在dplyr中重新编码和Mutate_all

rblastula - 未在 gmail 正文中正确呈现 rmarkdown

r - 使用 dplyr 将行名称保留为 id

r - 如何将同心椭圆的边缘与R图中的某些垂直线进行匹配

r - 抑制 r 图中的刻度

python - matplotlib 两个传说出情节

EC2 上的 RSelenium 和 Docker

r - R : Pass argument to glm inside an R function