-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtryout_olympics.R
55 lines (39 loc) · 1.2 KB
/
tryout_olympics.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
athletes <- read.csv("C:/Users/hafiznij/Downloads/archive/athlete_events.csv")
regions <- read.csv("C:/Users/hafiznij/Downloads/archive/noc_regions.csv")
athletes_region <- merge(athletes, regions)
# Medals per country on map -----------------------------------------------
# Medals per country:
best_country <- athletes_region %>%
filter(!is.na(Medal)) %>%
filter(Medal == "Gold") %>%
mutate(medal_bi = 1) %>%
group_by(region) %>%
count(medal_bi)
world_coordinates <- map_data("world") %>%
left_join(best_country) %>%
arrange(order)
ggplot(data = world_coordinates,
mapping = aes(x = long, y = lat, group = group)) +
coord_fixed(1.3) +
geom_polygon(aes(fill = n)) +
scale_fill_distiller(palette ="RdBu", direction = -1) + # or direction=1
ggtitle("Olympic medalists by country") +
theme_void()
# Intro -------------------------------------------------------------------
best_by_sport <- athletes_region %>%
filter(Medal == "Gold") %>%
group_by(Sport, region) %>%
count(Medal) %>%
group_by(Sport) %>%
slice(which.max(n))
p <- ggplot(
data = best_by_sport,
aes(
x = Sport,
y = n,
fill = region,
colour = region
)
) +
geom_point()
geom_col()