# R/Arrowhead.R In shape: Functions for Plotting Graphical Shapes, Colors

```##==============================================================================
##==============================================================================

Arrowhead <- function(x0, y0, angle=0, arr.length=0.4,
lcol="black", lty=1, arr.col=lcol, arr.lwd = 2, npoint = 5, ...) {

## points of polygon, as drawn in graph with x- and y- ranges -5,5

if ( arr.type=="curved") { # composed as section of circels

len <- 0.25*pi

x   <- seq(1.5*pi+len,1.5*pi,length.out=npoint)
x   <- rev(x)
mid <-c(rr[nrow(rr),1],0)
rd  <-rr[1,2]
x   <-seq(pi/2,3*pi/2,length.out=3*npoint)        #part of ellipse
rr <- rbind(rr,cbind(mid[1]-rd*0.25*cos(x),mid[2]-rd*sin(x)))
rr[,1] <- rr[,1]*2.6
rr[,2] <- rr[,2]*3.45
} else

if (arr.type=="triangle") {
x   <- c(-0.2,0.0,-0.2)
y   <- c(-0.1,0.0,0.1)
rr  <- 6.22*cbind(x,y)
} else

if (arr.type %in% c("circle","ellipse") )  {

if (arr.type=="circle")
arr.width=arr.length
x<- seq(0,2*pi,length.out=15*npoint)
}

rr[,1] <- rr[,1]-min(rr[,1])/2
rr[,1] <- rr[,1]-min(rr[,1])

user <- par("usr")
pcm  <- par("pin")*2.54

sy<- (user[4]-user[3])/pcm[2]
sx<- (user[2]-user[1])/pcm[1]
nr <- max(length(x0),length(y0),length(angle),
length(arr.length),length(arr.width),
length(lcol),length(lty),length(arr.col))
if (nr>1) {
x0         <- rep(x0        ,length.out=nr)
y0         <- rep(y0        ,length.out=nr)
angle      <- rep(angle     ,length.out=nr)
arr.length <- rep(arr.length,length.out=nr)
arr.width  <- rep(arr.width,length.out=nr)
lcol       <- rep(lcol      ,length.out=nr)
lty        <- rep(lty       ,length.out=nr)
arr.col    <- rep(arr.col   ,length.out=nr)
}
RR<-rr
for (i in 1:nr) {
## rotation around midpoint
dx <- rr[,1]*arr.length [i]
dy <- rr[,2]*arr.width  [i]

angpi <- angle[i] / 180 *pi
cosa  <-cos(angpi)
sina  <-sin(angpi)

RR[,1]<-  cosa*dx-sina*dy
RR[,2]<-  sina*dx+cosa*dy

## rescaling and transposing
RR[,1]<- x0[i] +RR[,1]*sx
RR[,2]<- y0[i] +RR[,2]*sy

## drawing...
polygon(RR,col=arr.col[i],border=lcol[i],lty=lty[i],lwd=arr.lwd, ...)
}
}
```

## Try the shape package in your browser

Any scripts or data that you put into this service are public.

shape documentation built on Feb. 9, 2018, 6:08 a.m.