Fat Arrows

You often want to add arrows to plots in order to draw attention to particular features. Here is a function called fat.arrows that uses locator(1) to identify the bottom of the point of a vertical fat arrow. You can modify the function to draw the arrow at any specified angle to the clicked point of its arrowhead. The default widths and heights of the arrow are 0.5 scaled x or y units and the default colour is red:

fat.arrow<-function(size.x=0.5,size.y=0.5,ar.col="red"){
size.x<-size.x*(par("usr")[2]-par("usr")[1])*0.1
size.y<-size.y*(par("usr")[4]-par("usr")[3])*0.1
pos<-locator(1)
xc<-c(0,1,0.5,0.5,-0.5,-0.5,-1,0)
yc<-c(0,1,1,6,6,1,1,0)
polygon(pos$x+size.x*xc,pos$y+size.y*yc,col=ar.col) }

We will use this function later in this chapter (p. 857).

Get The R Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.