-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript 2 - read in csv data
More file actions
35 lines (27 loc) · 1.29 KB
/
script 2 - read in csv data
File metadata and controls
35 lines (27 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# script 2 for the gitm: read in csv data
# uploaded the data from the 2016 files into R
distribution <- read.csv("Distribution.csv")
bodysize <- read.csv("BodySize.csv")
# merged the 2 files together into one table
chartdf <- merge(distribution, bodysize, by="Species")
# separated the merged data frame from where the tortoises lived
mainland <- chartdf[which(chartdf[,3]==0),]
shared <- chartdf[which(chartdf[,3]==1),]
islands <- chartdf[which(chartdf[,3]==2),]
# found the average body size in the tables
mean(mainland[,4])
mean(islands[,4])
mean(shared[,4])
# created a vector (list of #s or names) for them
meanvec <- c(mean(mainland[,4]), mean(islands[,4]), mean(shared[,4]))
namevec <- c("mainland", "islands", "shared")
# plotted them on a bar chart
barplot(meanvec, names.arg=namevec, main="mean values of body size")
# add standard deviation bars by calculating them
stanvec <- c(sd(mainland[,4]), sd(islands[,4]), sd(shared[,4]))
# https://stackoverflow.com/questions/49576344/adding-standard-deviation-to-barplot-in-r
barCenters <- barplot(height = meanvec, names.arg=namevec,
main = "mean values of body size", xlab = "Group", ylab = "bodysize",
ylim = c(0,150))
arrows(barCenters, meanvec-stanvec,
barCenters, meanvec+stanvec,angle=90,code=3)