这个问题在这里已经有了答案:
R: how do I draw a line with multiple arrows in it?
(5 个回答)
去年关闭。
我想为 R 中的图形定义自定义线型。
作为最小的工作示例,请考虑以下内容
plot(1:5,runif(5),type="l",lty="longdash")
这给了我一些随机线(如下图中的黑色虚线)。有没有办法让破折号看起来像小箭头(就像我用 illustrator 构建的红色例子)?
最佳答案
我继续@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")))
这产生了以下图表:
关于r - 由 R 图的小箭头组成的线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60456634/