-
Notifications
You must be signed in to change notification settings - Fork 2
/
prep.R
29 lines (22 loc) · 830 Bytes
/
prep.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
# Saving the top 500 billionaires in 2018-02-08 as a tibble ---------------
library(tidyverse)
vars = c(".t-rank" , ".t-name", ".t-nw", ".t-country", ".t-industry")
map_dfc(vars,
~xml2::read_html("https://www.bloomberg.com/billionaires/") %>%
rvest::html_nodes(.x) %>%
rvest::html_text() %>%
tibble() %>%
magrittr::set_colnames(slice(., 1)) %>%
slice(-1)) %>%
rename(Total_Net_Worth = `Total net worth`) %>%
mutate(TNW = parse_number(Total_Net_Worth)) %>%
print() -> billionaires
devtools::use_data(billionaires, overwrite = TRUE)
library(gglorenz)
ggplot(billionaires, aes(TNW)) +
stat_lorenz()
ggplot(billionaires, aes(TNW)) +
stat_lorenz(desc = TRUE) +
coord_fixed() +
geom_abline(linetype = "dashed") +
theme_minimal()