0

I currently have a substantial data set and have created a scatterplot which looks into the relationship between territory perimeter and path complexity (tortuosity), using the code:

plot(Tortuosity~Perimeter, data=TR, xlab="Territory perimeter (m)", ylab="Path tortuosity",pch=19,cex.lab=0.85,cex.axis=0.85,cex=0.85)

The TR dataframe consists of the following information, where Prm. represents perimeter and T. represents Tortuosity

Prm.    T.
198.58  0.45
198.58  0.63
198.58  0.24
198.58  0.32
198.58  0.6
198.58  0.49
134.62  0.3
134.62  0.39
134.62  0.12
134.62  0.09
134.62  0.25
134.62  0.45
134.62  0.44
134.62  0.84
128.07  1.99
144.32  0.72
144.32  1.01
144.32  1.09
144.32  1.15
189.96  0.55
189.96  0.76
189.96  0.78
113.74  0.67
113.74  0.73
113.74  0.69
113.74  0.61
134.15  0.39
134.15  0.26
134.15  1.37
156.11  1.1
156.11  0.67
156.11  0.98
88.41   1.09
88.41   0.87
88.41   0.47
88.41   0.8
88.41   0.52
86.71   1.47
94.4    0.92
94.4    1.23
94.4    0.96
94.4    0.56
94.4    0.82
87.53   1.22
10.85   
93.22   1.67
90.13   1.26
90.13   0.67
198.58  1.46
198.58  0.99
198.58  0.68
198.58  0.53
134.62  0.12
134.62  0.32
134.62  0.73
134.62  1.18
144.32  1.03
189.96  0.86
189.96  0.43
189.96  0.42
113.74  0.9
113.74  0.7
134.15  0.97
156.11  0.85
156.11  0.45
156.11  0.84
156.11  0.8
88.41   0.81
88.41   1.74
88.41   0.98
88.41   0.75
86.71   1.1
94.4    0.69
94.4    0.63
94.4    0.67
94.4    0.59
94.4    0.82
87.53   0.64
87.53   0.7
10.85   2.73
10.85   
10.85   2.73
10.85   0.85
10.85   1.01
93.22   1.67
90.13   0.89
90.13   0.74
90.13   0.59
90.13   0.58
90.13   1.14
90.13   0.93
154.33  0.97
154.33  0.53
154.33  0.62

However I want to add standard error 'whiskers' to each point (see below for the graph). enter image description here

Is there a way of doing this automatically, similar to the lineplot.CI() function for interactive effect graphs? Apologies for the length of information but I am not sure what will be exactly of use..

user3170629
  • 489
  • 3
  • 12
  • 21
  • Are you only looking for a base R implementation or are other packages like `ggplot2` valid? – talat Jul 20 '14 at 11:46
  • 1
    For examples of error bars in `ggplot2` see [the documentation](http://docs.ggplot2.org/current/geom_errorbar.html) – talat Jul 20 '14 at 11:59
  • I was hoping to stick to the base R implementation, but I am open to other packages. The method from ggplot2 seems to involve working out the SEs for each point, as there are so many is there a way of doing it automatically? – user3170629 Jul 20 '14 at 12:04
  • 3
    Please consider including a *small* [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so we can better understand and more easily answer your question. – Ben Bolker Jul 20 '14 at 13:06

1 Answers1

0

Here's how I would do it using ggplot2 but I have to say that the plot is not very readable with the error bars included. Anyway, the manual effort is not high to produce the bars.

library(ggplot2)
library(dplyr)

TR %>% 
  group_by(Prm.) %>%
  mutate(sd = sd(T.)) %>%
  ggplot(., aes(x = Prm., y = T.)) +
  geom_point() +
  geom_errorbar(aes(ymin = T. - sd, ymax = T. + sd), width = 2)

plot

talat
  • 68,970
  • 21
  • 126
  • 157