-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathwgoitg01.Rmd
119 lines (91 loc) · 3.91 KB
/
wgoitg01.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
---
title: "WGOITG practice"
author: "Jilung Hsieh"
date: "`r Sys.Date()`"
output: html_document
---
# Set up
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.width = 4, fig.asp = 0.4)
```
```{r loading-libs}
library(tidyverse)
options(stringsAsFactors = F)
# install.packages("gghighlight")
library(gghighlight)
```
# Median of net worth by age group
The news: <https://www.nytimes.com/2021/05/11/learning/lesson-plans/teach-about-inequality-with-these-28-new-york-times-graphs.html>
1. `names(toplot)` should be `[1] "year" "Category" "Net_worth" "increase"`
2. Select `year`, `Category`, and `Net_Worth`
3. Grouped by `Category`
1. Sort by `year` (using `arrange`)
2. Mutate a new column `increase`
4. ungroup() then plotting
```{r}
toplot <- read_csv("data/nytdata/interactive_bulletin_charts_agecl_median.csv")
# YOUR CODE SHOULD PIPELINE BEGINING HERE
```
```{r vis-net-worth}
toplot %>%
ggplot() + aes(year, increase, color = Category) +
geom_line() +
gghighlight(Category %in% c("65-74", "35-44")) +
theme_minimal() +
scale_x_continuous(breaks = NULL) +
theme(panel.background = element_rect(fill = "whitesmoke",
colour = "whitesmoke",
size = 0.5, linetype = "solid"))
```
# UNICEF-Optimistic
<https://www.nytimes.com/2021/11/17/upshot/global-survey-optimism.html> <https://changingchildhood.unicef.org/about>
1. relabel by mutate and `ordered()` with levels and labels\
`mutate(var1 = ordered(var2, levels = c(…), labels = c(…))`
2. `count()` and `spread()` then `mutate()` a new var `perc` standing for answering "world will be better!" proportion.
3. `spread()` by `age` group and its `perc`
4. `rename` columns
5. then plotting
```{r young-people-optimistic-scatter, fig.cap = '(ref:young-people-optimistic)'}
toplot <- read_csv("data/nytdata/unicef-changing-childhood-data.csv") %>%
select(country = WP5, age = WP22140, bw = WP22092) %>%
mutate(country = ordered(country,
levels=c(1, 3, 4, 10, 11, 12, 13, 14, 17, 29,
31, 33, 35, 36, 60, 61, 77, 79, 81, 87, 165),
labels=c("USA", "Morocco", "Lebanon", "Indonesia",
"Bangladesh", "UK", "France", "Germany",
"Spain", "Japan", "India", "Brazil",
"Nigeria", "Kenya", "Ethiopia", "Mali",
"Ukraine", "Cameroon", "Zimbabwe",
"Argentina", "Peru")))
# YOUR CODE SHOULD PIPELINE BEGINING HERE
```
```{r}
toplot %>%
ggplot() + aes(`40+y`, `15-24y`, label = country) +
geom_point(color = "skyblue", size = 2) +
xlim(0, 1) + ylim(0,1) +
geom_text(hjust = -0.1, vjust = -0.5) +
geom_abline(intercept = 0, slop = 1,
color="lightgrey", alpha=0.5, linetype="dashed") +
theme_minimal() +
theme(aspect.ratio=1)
```
# Global Carbon Projects
[Who Has The Most Historical Responsibility for Climate Change? - The New York Times (nytimes.com)](https://www.nytimes.com/interactive/2021/11/12/climate/cop26-emissions-compensation.html?campaign_id=29&emc=edit_up_20211112&instance_id=45236&nl=the-upshot®i_id=52022771&segment_id=74222&te=1&user_id=7cc6d9cd8f523e256ae41958ee8a9cb5)
```{r}
totreemap <- read_csv("WGOITG/nytdata/GCB2021v34_MtCO2_flat.csv") %>%
drop_na(`Total`) %>%
filter(!Country %in% c("Global", "International Transport")) %>%
filter(Year==2020) %>%
arrange(desc(`Total`)) %>%
mutate(perc = Total/sum(Total)) %>%
slice(1:20)
library(treemapify)
totreemap %>%
ggplot() + aes(area = perc, fill=`Per Capita`, label=Country) +
geom_treemap() +
geom_treemap_text(color="white",
place="centre",
grow=TRUE
)
```