-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapterfour.R
76 lines (49 loc) · 1.83 KB
/
chapterfour.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
library(fivethirtyeight)
library(nycflights13)
library(dplyr)
#library(skimr)
library(knitr)
library(ggplot2)
library(tidyr)
library(readr)
dem_score <-read_csv("https://moderndive.com/data/dem_score.csv")
dem_score
View(drinks)
drinks_smaller <- drinks %>%
filter(country %in% c("USA", "China", "Italy", "Saudi Arabia", "Swaziland","South Africa"))%>%
select(-total_litres_of_pure_alcohol)%>%
rename(beer=beer_servings, spirit=spirit_servings, wine=wine_servings)
View(drinks_smaller)
dat_long <- drinks_smaller %>%
gather("Stat", "Value", -country)
ggplot(data=dat_long, mapping = aes(x=country, y=Value, fill=Stat))+
geom_bar(stat="identity", position=position_dodge())
drinks_smaller_tidy <-drinks_smaller %>%
pivot_longer(names_to = "type",
values_to= "servings",
cols=-country)
View(drinks_smaller_tidy)
ggplot(drinks_smaller_tidy,aes(x=country, y=servings, fill=type))+
geom_bar(position = "dodge", stat = "identity")
airlines_safety_smaller<- airline_safety %>%
select(airline, starts_with("fatalities"))
airlines_safety_smaller
arlines_safety_tidy <- airlines_safety_smaller %>%
pivot_longer(names_to = "Years",
values_to="Fatalities",
cols=-airline)
arlines_safety_tidy
ggplot(arlines_safety_tidy,aes(x=airline, y=Fatalities, fill=Years))+
geom_bar(position = "dodge", stat = "identity")
guat_dem <- dem_score %>%
filter(country=="Guatemala")
guat_dem
guat_dem_tidy <- guat_dem %>%
pivot_longer(names_to = "year",
values_to ="democracy_score",
cols= -country,
names_transform = list(year = as.integer))
guat_dem_tidy
ggplot(guat_dem_tidy, aes(x=year, y=democracy_score))+
geom_line()+
labs(x="Year", y="Democracy Score")