Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change arrowhead of arrows()

Tags:

plot

r

i wonder if it is possible to change the arrowhead of an arrow drawn with arrows(). I looked through the documentation but all I found is that I can change the end of a line but not of an arrow?

plot(c(1:10)) arrows(0,0,10,10) 

Any help is appreciated :)

like image 718
Sarah West Avatar asked Apr 20 '11 13:04

Sarah West


People also ask

How do you make an arrow in R?

To create an arrow R, we can use plot function and arrows function. We just need to understand all the coordinate values that should be passed inside the arrows function. For example, if we have two vectors that contains values from 1 to 10 then the arrow can be created by using arrows function as arrows(1,1,10,10).


2 Answers

as explained in ?arrow , you can use length and angle to change the appearance of standard arrows. With lwd you can change the thickness, exactly like in lines(). Also lty works, although the result is often not exactly nice.

A whole set of examples :

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)) ) 
like image 135
Joris Meys Avatar answered Sep 22 '22 12:09

Joris Meys


Karline Soetaert's package shape is useful for this purpose:

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) 

The default is a filled, curved arrowhead that's pleasant to look at:

enter image description here

Gotta love CRAN!

like image 43
Andy Barbour Avatar answered Sep 22 '22 12:09

Andy Barbour