-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphing2.R
76 lines (68 loc) · 2.89 KB
/
graphing2.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
require(tidyverse)
require(ggthemes)
df <- read_csv("World_Data.csv") %>%
select(-X1) %>%
filter(Year >= 1990)
colnames(df) <- c("Year", "Population", "Area with Permanent Snow/Glaciers",
"Major livestock density in agricultural areas",
"Total Emissions of CO2eq",
"Emissions of CO2eq from Agriculture",
"Emissions of CO2eq from Energy Production",
"Emissions of CO2eq from Land Use Sources",
"Emissions of CO2eq from Forests",
"Emissions of CO2eq from Waste",
"Emissions of CO2eq from Other Sources",
"Emissions of CO2eq from Transportation",
"Use of Nitrogen per area of cropland",
"Use of Phosphate per area of cropland",
"Use of Potash per area of cropland",
"Use of Pesticides per area of cropland",
"Food supply",
"Industrial Production",
"Average Annual Precipitation",
"Total Renewable Water Resources",
"Total Renewable Water Resources Per Capita",
"Built-up Land (Eco. Footprint)",
"Carbon (Eco. Footprint)",
"Cropland (Eco. Footprint)",
"Fishing Grounds (Eco. Footprint)",
"Forest Products (Eco. Footprint)",
"Grazing Land (Eco. Footprint)",
"Total (Eco. Footprint)",
"Built-up Land (Biocapacity)",
"Carbon (Biocapacity)",
"Cropland (Biocapacity)",
"Fishing Grounds (Biocapacity)",
"Forest Products (Biocapacity)",
"Grazing Land (Biocapacity)",
"Total (Biocapacity)",
"Birth Rate",
"Death Rate")
df[3:ncol(df)] <- lapply(df[3:ncol(df)], scale)
df <- df %>%
gather(key = "Measure", value = "Value", -Year, -Population)# %>%
#mutate(Value = scale(Value))# %>%
# filter(Measure %in% c("Total (Eco. Footprint, gha)", "Total (Biocapacity, gha)", "Carbon (Eco. Footprint, gha)", "Forest Products (Biocapacity, gha)", "Cropland (Biocapacity, gha)", "Cropland (Eco. Footprint, gha)", "Forest Products (Eco. Footprint, gha)", "Grazing Land (Biocapacity, gha)", "Fishing Grounds (Biocapacity, gha)"))
p <- df %>%
ggplot(aes(x = Year, y = Value, color = Measure)) +
geom_line() +
theme_fivethirtyeight() +
theme(text = element_text(family = "CMU Serif", size = 20),
legend.position = "bottom",
legend.text = element_text(size = 12),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.line.y = element_blank(),
axis.title = element_text(),
# plot.title = element_text(size = 25, hjust = 0.5),
plot.title = element_blank(),
legend.title = element_blank(),
plot.background = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
legend.background = element_blank(),
legend.key = element_blank()) +
guides(color = guide_legend(ncol = 3)) +
ggtitle("Sample Factor Data by Year")
print(p)
ggsave(file="test.svg", width = 20, height = 14)