11# ' Add arrows to a plot.
22# '
3- # ' Draw arrows between pairs of points. Arrows drawn are fully customizable by using parameters of `polygon` function .
3+ # ' Draw a custom arrows between pairs of points.
44# '
55# ' @export
66# '
1414# ' @param cex.shr the magnification coefficient to be used to change the height of arrows towards their heads.
1515# ' @param cex.hl the magnification coefficient to be used for the lengths of arrows' head.
1616# ' @param cex.hh the magnification coefficient to be used for the heights of arrows' head.
17- # ' @param prophead logical. If TRUE arrows are drawn with head proportionnal to the length of the arrows.
17+ # ' @param prophead logical. If TRUE arrows are drawn with head proportional to the length of the arrows.
1818# ' @param twoheaded logical. If TRUE two-headed arrows are drawn, default is FALSE.
1919# ' @param ... additional arguments to be passed to `polygon` function.
2020# '
3535# ' arrows2(runif(2), runif(2), x1=runif(2), y1=runif(2), prophead=FALSE, lty=3)
3636
3737
38- arrows2 <- function (x0 , y0 , x1 = x0 , y1 = y0 , off0 = 0 , off1 = off0 , cex.arr = 1 ,
38+ arrows2 <- function (x0 , y0 , x1 = x0 , y1 = y0 , off0 = 0 , off1 = off0 , cex.arr = 1 ,
3939 cex.shr = 1 , cex.hh = 1 , cex.hl = 1 , prophead = TRUE , twoheaded = FALSE , ... ) {
4040 stopifnot(all(c(off0 , off1 )^ 2 < 1 ))
41- # # ---- Format checkings / adjusting vectors sizes
41+ # # ---- Format checking / adjusting vectors sizes
4242 argn <- c(" x0" , " y0" , " x1" , " y1" )
4343 argo <- list (x0 , y0 , x1 , y1 )
4444 sz <- max(sapply(list (x0 , y0 , x1 , y1 ), length ))
@@ -48,7 +48,7 @@ arrows2 <- function(x0, y0, x1 = x0, y1 = y0, off0 = 0, off1 = off0, cex.arr = 1
4848 rx <- (x1 - x0 )
4949 ry <- (y1 - y0 )
5050 distpt <- sqrt(rx * rx + ry * ry )
51- # ----- Checkings
51+ # ----- Checking
5252 pb <- which(distpt == 0 )
5353 if (length(pb ) > 0 ) {
5454 warning(" Zero-length arrows are skipped." )
@@ -84,15 +84,16 @@ arrows2 <- function(x0, y0, x1 = x0, y1 = y0, off0 = 0, off1 = off0, cex.arr = 1
8484 sqptx <- rep(x0 [i ], 7 ) + c(0 , lg2 , lg2 , lg1 , lg2 , lg2 , 0 )
8585 sqpty <- rep(y0 [i ], 7 ) + c(hg1 , hg2 , hg3 , 0 , - hg3 , - hg2 , - hg1 )
8686 } else {
87- sqptx <- rep(x0 [i ], 12 ) + c(0 , lg3 , lg3 , 0.5 * lg1 , lg2 , lg2 , lg1 , lg2 ,
87+ sqptx <- rep(x0 [i ], 12 ) + c(0 , lg3 , lg3 , 0.5 * lg1 , lg2 , lg2 , lg1 , lg2 ,
8888 lg2 , 0.5 * lg1 , lg3 , lg3 )
89- sqpty <- rep(y0 [i ], 12 ) + c(0 , hg3 , hg2 , hg1 , hg2 , hg3 , 0 , - hg3 , - hg2 ,
89+ sqpty <- rep(y0 [i ], 12 ) + c(0 , hg3 , hg2 , hg1 , hg2 , hg3 , 0 , - hg3 , - hg2 ,
9090 - hg1 , - hg2 , - hg3 )
9191 }
9292 # # ----
93- ptcoord <- rotation(sqptx , sqpty , rot = anglept [i ], xrot = x0 [i ], yrot = y0 [i ],
93+ ptcoord <- rotation(sqptx , sqpty , rot = anglept [i ], xrot = x0 [i ], yrot = y0 [i ],
9494 rad = TRUE )
9595 graphics :: polygon(ptcoord $ x , ptcoord $ y , ... )
9696 }
97+ # # ----
9798 invisible (NULL )
9899}
0 commit comments