I am trying to plot an arrow on a base R plot. I would like the arrow head to be a small equilateral triangle. I hoped the arr.type
argument of arrows
would allow an option for a small arrow, but that doesn't seem to be the case.
arrows(as.Date('1-Feb-15', "%d-%b-%y"), 50, as.Date('1-May-15', "%d-%b-%y"), 50, col = 'dark orange', lwd=5, arr.type = 'simple', arr.width=3)
Is there a simple way to make the arrow head small?
I don't know of a way to get a filled arrow head with base arrows
. However, you can do it with the Arrows
function from the shape
package:
library(shape)
plot(NA,NA, xlim=c(0,10), ylim=c(0,10))
Arrows(1,3,4,6,lwd=2, arr.type="triangle")
Arrows(5,7,6,9, arr.type="triangle", arr.width=0.5)
grid
graphics also has filled arrows. Here's a ggplot2 example. type="closed"
gives filled arrow heads. angle
and length
set the arrows' size and shape:
library(ggplot2)
n=8
ggplot(mtcars[1:n,][order(mtcars$wt[1:n]),], aes(x=wt, y=mpg, xend=lead(wt), yend=lead(mpg))) +
geom_segment(arrow=arrow(type="closed",
angle=seq(10,80, length=n),
length=unit(seq(8,4,length=n),"mm")))
In case you want to stick to base R, you can read in the documentation that one can change the "width" and "height" of the head with the parameters "angle" and "length":
https://stat.ethz.ch/R-manual/R-patched/library/grid/html/arrow.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With