-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbirds2.R
More file actions
42 lines (25 loc) · 1.31 KB
/
birds2.R
File metadata and controls
42 lines (25 loc) · 1.31 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
36
37
38
39
40
41
42
setwd(r"{C:\Users\salba\Documents\Big Data Club\R For Data Analysis}")
### Load the Tidyverse
# install.packages("tidyverse")
library(tidyverse)
#Also load a personal favorite - gridExtra
library(gridExtra)
df <- read_csv("birds.csv")
head(df)
colnames(df)
summary(df)
g1 <- ggplot(df) + geom_density(aes(x = wingspan), fill = "lightblue") + xlab("Wingspan") + theme_light()
g2 <- ggplot(df) + geom_histogram(aes(x = egg_capacity), fill = "black") + xlab("Egg Capacity") + theme_light()
grid.arrange(g1, g2)
pred <- df %>% group_by(predator) %>% summarize(Wingspan = mean(wingspan, na.rm = TRUE), se = sd(wingspan, na.rm = TRUE) / sqrt(n()))
ggplot(pred) + geom_col(aes(x = predator, y = Wingspan), fill = "lightblue") +
geom_errorbar(aes(x = predator, ymin = Wingspan - se, ymax = Wingspan + se), width = 0.2) +
theme_light()
summary(df)
hab <- df %>% select(common_name, forest, grassland, wetland, egg_capacity) %>%
mutate(nhab = forest + grassland + wetland) %>%
filter(nhab == 1)
forest <- hab %>% filter(forest) %>% summarize(forest = mean(egg_capacity))
grassland <- hab %>% filter(grassland) %>% summarize(grassland = mean(egg_capacity))
df2 <- bind_cols(forest, grassland) %>% gather()
ggplot(df2) + geom_col(aes(x = key, y = value)) + xlab("Habitat") + theme_light()