forked from mkuzak/datacarpentry-r-visualisation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
00-intro.Rmd
83 lines (64 loc) · 2.51 KB
/
00-intro.Rmd
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
layout: page
title: Visalizing data with R
subtitle: subtitle
minutes: 1h
---
```r
library(ggplot2)
library(magrittr)
library(dplyr)
surveys <- read.csv("http://files.figshare.com/1919744/surveys.csv")
plot(x=surveys$weight, y=surveys$hindfoot_length)
surveys %>% ggplot(aes(weight, hindfoot_length)) +
geom_point()
surveys %>% ggplot(aes(weight, hindfoot_length)) +
stat_binhex(bins=50) +
scale_fill_gradientn(trans="log10",
colours = heat.colors(10, alpha=0.5))
# there are a lot of species with low counts,
# lets make a barpolot and see
species_counts <- surveys %>%
filter(!is.na(weight)) %>%
group_by(species_id) %>%
summarise(n=n())
surveys %>% ggplot(aes(factor(species_id))) +
geom_bar() +
scale_y_continuous(trans = 'log10')
high_counts <- species_counts %>%
filter(n > 10) %>%
select(species_id)
surveys_subset <- surveys %>%
filter(species_id %in% high_counts$species_id)
surveys_subset %>% ggplot(aes(factor(species_id), weight)) +
geom_boxplot()
# add jitter to see how many points are per boxplot
surveys_subset %>% ggplot(aes(factor(species_id), weight)) +
geom_boxplot() +
geom_jitter(alpha=0.1)
# different way to look at it is violoin plot
surveys_subset %>% ggplot(aes(factor(species_id), weight)) +
geom_violin()
# challange would be do the same for length
# counts in time per species
# remove unannotated species
surveys_subset %<>% filter(species_id != "")
# summarise counts per year per species
yearly_counts <- surveys_subset %>%
group_by(year, species_id) %>%
summarise(count=n())
yearly_counts %>% ggplot(aes(x=year,
y=count,
group=species_id,
color=species_id)) +
geom_line()
yearly_counts %>% ggplot(aes(x=year,
y=count,
color=species_id)) +
geom_line()
yearly_counts %>% ggplot(aes(x=year,
y=count,
color=species_id)) +
geom_line() +
facet_wrap(~species_id)
```