【问题标题】:Can arrows() draw an arrow head only?arrows() 只能画箭头吗?
【发布时间】:2015-08-05 15:42:23
【问题描述】:

有没有办法用 R 图形包绘制没有“主体”的箭头?

plot(0, type="n", ann=FALSE, axes=FALSE, xlim=c(0,1), ylim=c(0,1))
arrows(x0=0.5, y0=0.2, x1=0.5, y1=0.9) # without the line '|'?

所以我基本上只对绘制箭头(或三角形,例如)感兴趣, 但它必须与 R 图形包(基本图形)一起使用。我希望 避免自己画箭头(segments() 会很好 怎么做?)。

【问题讨论】:

  • 你可以试着让它变得非常小:arrows(x0=0.5, y0=0.9-(1e-3), x1=0.5, y1=0.9)。至少我看不到....
  • 这是一个很好的“hack”,正是我想要的,非常感谢。你能把它写成一个答案让我接受吗?

标签: r graphics


【解决方案1】:

你可以试试这个简单的东西:

arrowhead <- function(x0, y0, x1, y1, length = 0.25, angle = 30,...){
    t = atan2(y1-y0, x1-x0)
    a1 = pi+t+angle*pi/180
    a2 = pi+t-angle*pi/180
    e1x = x1 + length*cos(a1)
    e1y = y1 + length*sin(a1)
    e2x = x1 + length*cos(a2)
    e2y = y1 + length*sin(a2)
    lines(c(e1x,x1,e2x),c(e1y,y1,e2y),...)
}

这很容易改进。与arrows 的最大区别在于箭头大小以绘图单位而不是“英寸”为单位。您可能可以通过使用xinch 来解决这个问题。

lines 替换为polygon 并在... 参数中指定颜色以获得实心箭头。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-23
    • 2018-11-18
    • 2014-12-13
    • 1970-01-01
    相关资源
    最近更新 更多