更改箭头的箭头()

Sar*_*est 24 plot r

我想知道是否有可能改变用箭头绘制的箭头arrows().我查看了文档,但我发现的是我可以更改一行而不是一行箭头?

plot(c(1:10))
arrows(0,0,10,10)
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏:)

Jor*_*eys 18

如中所述?arrow,您可以使用lengthangle更改标准箭头的外观.有了lwd你可以改变线条的厚度,酷似().也lty有效,虽然结果往往不太好.

一整套例子:

plot(c(0:10),type="n")

arrows(1,0,2,1,length=0.2,angle=20)
arrows(1,1,2,2,length=0.1,angle=40,lwd=3)

invisible(mapply(arrows,
        rep(c(3,6),each=4),rep(3:6,2),
        rep(c(5,8),each=4),rep(5:8,2),
        angle=seq(10,40,length.out=8),
        length=rep(seq(0.1,0.3,length.out=4),2),
        lwd=rep(1:4,each=2))
)
Run Code Online (Sandbox Code Playgroud)


And*_*our 15

Karline Soetaert的软件包shape可用于此目的:

library(shape)
plot(c(0,2),c(-2,2), col=NA)
Arrows(c(0,1.7),c(1.3,-1.8),c(0.8,1.1),c(1.2,-1), lwd=2)
Run Code Online (Sandbox Code Playgroud)

默认是一个充满弯曲的箭头,看起来很舒服:

在此输入图像描述

得爱CRAN!

  • 你知道这些箭头是否也可以用于ggplot2图中吗? (4认同)

Gre*_*now 6

如果其他的答案不使用箭头键的功能给你的箭足够的控制,你可以使用功能my.symbols,从TeachingDemos包.这允许您创建自己的自定义箭头并绘制它们.

该函数ms.arrows在同一个包中显示了一种执行此操作的方法:您可以修改该函数(或其他ms.*函数)以创建所需的任何类型的箭头,然后my.symbols用于绘制它们.

编辑

这是一个要求的例子:

library(TeachingDemos)

ms.arrowhead <- function(angle, ...) {
  xy <- cbind( c(-1, -0.75, -1, 0), 
               c(-0.5, 0, 0.5, 0) )
  xy <- xy %*% matrix(c(cos(angle),-sin(angle),sin(angle),cos(angle)), 2)
  xspline(xy, shape=c(0, -1, 0, 0), open=FALSE, ...)
}

plot(1:10, 1:10)
my.symbols(1:10, 1:10, ms.arrows, angle=seq(pi, 0, length=10),
           col='blue', adj=1, length=0, symb.plots=TRUE)
my.symbols(1:10, 1:10, ms.arrowhead, angle= seq(pi, 0, length=10), 
           col='green', inches=0.5, lwd=2, symb.plots = TRUE)
Run Code Online (Sandbox Code Playgroud)

这使用该xspline功能绘制一个带有弯曲后部的三角形作为箭头.可以修改这些点以获得不同形状的箭头,或者可以使用另一种方法来形成该形状.