Locator arrows in R

location-pixabay-1200x800-100728584-large

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
plot(1:10,1:10)

##Place locations of two arrows
loc.arrow<-locator(4)

##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
loc.arrow
$x
[1] 2.828149 2.798691 5.332089 7.070118
$y
[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 Head of Data Science and Insights at www.mindfolio.com. I am a lover of R and consider myself an Rtist in data visualisations.

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 )

w

Connecting to %s