Locator arrows in R


When creating advanced visualisations in R, determining the coordinates of where to put your arrows or text can be a tricky thing. Luckily, there is an awesome function in R called ‘locator‘.

##Make a plot

##Place locations of two arrows

##Once this line is run, the console run line should be flashing.
#click on a start and stop point of the where the first arrow should go,
##then the start and stop point on the second arrow.
##The console run line should then stop flashing

##run the loc.arrow line
##in this case
[1] 2.828149 2.798691 5.332089 7.070118
[1] 4.646730 8.367149 7.477484 4.201897

#Adding the arrows to the plot
with(loc.arrow, arrows(x0=x[seq(1,4,by=2)], x1=x[seq(2,4,by=2)],
y0=y[seq(1,4,by=2)], y1= y[seq(2,4,by=2)]))


Author: Jamie Samson

I am a data scientist and passionate R user.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s