9
$\begingroup$

I want to be able to compare the angles of neighbours in a herd of hippos. I have data for the x and y coordinates and the angles that they are facing (using imageJ, angles are between -180 and 180 with 0 being a horizontal straight line across the middle of the image). I have plotted the $g(r)$ function to see whether my hippos 'like' to orient themselves towards individuals that are nearby, but I would love to be able to compute a visual representation of their orientation in the herd using R.

Any help would be much appreciated, I'm not really R literate yet!

$\endgroup$
5
  • 1
    $\begingroup$ Take a look at the circular package. It has several plots that may help you, and also some nice functions. $\endgroup$
    – Peter Flom
    Mar 1, 2012 at 18:31
  • 1
    $\begingroup$ I would be interested in learning more about what "$g(r)$" represents and how it is calculated. $\endgroup$
    – whuber
    Mar 1, 2012 at 19:32
  • 1
    $\begingroup$ This question appears to be off-topic because it is about coding in R and not statistics. $\endgroup$
    – John
    Nov 14, 2013 at 1:39
  • $\begingroup$ Please edit your question to more clearly emphasize the statistical/data-vizualization aspects of your question over the 'what lines of R code should I type' aspects. Could you also clarify what $g$ is please? $\endgroup$
    – Glen_b
    Nov 14, 2013 at 2:38
  • $\begingroup$ The question is not so unclear "How can I produce a plot showing the directional angles of my points?" but it is off-topic since it is about 'production'. If we just change the title into "How should I plot the directional angles of my points?" then this question may be released from the closing tag and be open for people to give their thoughts on plotting data points while including directional information. $\endgroup$ Feb 8, 2018 at 17:11

2 Answers 2

15
$\begingroup$

It sounds like the data consist of vectors of (x,y) coordinates and the angles. Let's simulate some as an example:

set.seed(43)
x <- rnorm(50)
y <- rnorm(50)
angles <- runif(50, min=-pi, max=pi)

Plot the locations:

plot(x, y, pch=19, cex=0.8, col="Blue")

Add arrows to show the orientations at these points:

length <- 0.2
arrows(x, y, x1=x+length*cos(angles), y1=y+length*sin(angles), 
       length=0.05, col="Gray")

Hippos

$\endgroup$
3
  • 1
    $\begingroup$ This has really helped thank you so much! I'm working on adapting it for my data and am looking forward to seeing the plot output :) Thanks again! $\endgroup$
    – Cara
    Mar 2, 2012 at 10:12
  • $\begingroup$ The code should be corrected as R always works with angles in radians: cos(angles*pi/180) and sin(angles*pi/180) with angles between 0 and 360. $\endgroup$
    – DJack
    Jan 21, 2018 at 8:42
  • $\begingroup$ @DJack Thank you for pointing that out. Fortunately in this case it makes little difference (and therefore I don't need to recompute the example), because a uniform distribution on $[-180,180]$ radians isn't much different than a uniform distribution on $[-\pi,\pi]$ radians (modulo $2\pi$), but it's important to get such details computationally correct. $\endgroup$
    – whuber
    Jan 21, 2018 at 15:55
3
$\begingroup$

To add to the answer by @whuber. The ms.arrows and my.symbols functions in the TeachingDemos package for R might be of interest. They would also plot the arrows but you can give the anges directly rather than computing sine and cosine, it also makes it easier if you want the arrows centered on the points rather than originating from the points.

$\endgroup$
1
  • $\begingroup$ Thank you so much everyone, I'll send this to my supervisor and we shall have a go at all your suggestions! $\endgroup$
    – Cara
    Mar 1, 2012 at 20:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.