-
Notifications
You must be signed in to change notification settings - Fork 0
/
vizwhiz2.R
94 lines (73 loc) · 2 KB
/
vizwhiz2.R
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
84
85
86
87
88
89
90
91
92
93
94
#other geoms to illustrate variability
#boxplots----------
plotbeaches %>%
na.omit() %>%
filter(buggier_site == "TRUE") %>%
ggplot(aes(x = site, y= logbeachbugs)) +
geom_boxplot() +
coord_flip()
#violin plots----------
plotbeaches %>%
na.omit() %>%
filter(buggier_site == "TRUE") %>%
ggplot(aes(x = year, y= logbeachbugs, color = site)) +
geom_violin() +
facet_wrap(~ site)
#histogram ---------------
#https://ggplot2.tidyverse.org/reference/geom_histogram.html
plotbeaches %>%
na.omit() %>%
filter(logbeachbugs > 0,
site == "Clovelly Beach",
year == "2018") %>%
ggplot(aes(x = beachbugs)) +
geom_histogram(binwidth= 5)
#layering points on boxplot/violins----------
plotbeaches %>%
na.omit() %>%
filter(buggier_site == "TRUE") %>%
ggplot(aes(x = site, y= logbeachbugs)) +
geom_boxplot() +
geom_point(aes(color= year)) +
coord_flip()
plotbeaches %>%
na.omit() %>%
filter(site == "Clovelly Beach") %>%
ggplot(aes(x = year, y= logbeachbugs)) +
geom_violin() +
geom_quasirandom(aes(colour = buggier_site))
#viz whiz 3bars and columns--------------
#bar for when the height of the bar is a count
plotbeaches %>%
ggplot(aes(x=year)) +
geom_bar()
#differentiating with facet
plotbeaches %>%
ggplot(aes(x=year)) +
geom_bar() +
facet_wrap(~ site)
#differentiating with color
plotbeaches %>%
ggplot(aes(x=year, fill= site)) +
geom_bar()
#columns for when the height of the bar is a value you calculated
plotbeaches %>%
group_by(site) %>%
summarise(meanbugs = mean(beachbugs, na.rm = TRUE)) %>%
ggplot(aes(x=site, y= meanbugs)) +
geom_col() +
coord_flip()
library(lubridate)
plotbeaches$date <- dmy(plotbeaches$date)
glimpse(plotbeaches)
#lines
plotbeaches %>%
filter(year == "2018", site == "Coogee Beach") %>%
ggplot(aes(x= date, y= beachbugs)) +
geom_line()
#lines
plotbeaches %>%
group_by(month) %>%
summarise(meanbugs = mean(beachbugs, na.rm= TRUE)) %>%
ggplot(aes(x= month, y= meanbugs)) +
geom_line(group = month)