Skip to content

Instantly share code, notes, and snippets.

@jnolis
Created July 15, 2020 18:20
Show Gist options
  • Save jnolis/c35be3ea08d4ba0c8bc75bc88b44f806 to your computer and use it in GitHub Desktop.
Save jnolis/c35be3ea08d4ba0c8bc75bc88b44f806 to your computer and use it in GitHub Desktop.
library(tidyverse)
wealth <- tibble(
name = c(
"Jeff Bezos", "Bill Gates", "Mark Zuckerberg", "Bernard Arnault", "Steve Ballmer",
"Larry Page", "Elon Musk",
"Sergey Brin", "Mukesh Ambani", "Warren Buffet"
),
worth = c(184, 115, 94.5, 90.8, 74.6, 72.4, 71.6, 69.7, 69.4, 68.6),
increase = c(0.65, 0.4, 0.18, -0.11, .36, .14, 1.53, .13, .19, -0.21)
) %>%
mutate(
old_worth = round(worth / (increase + 1), digits = 1),
font_face_bold = if_else(name == "Elon Musk", "bold", "plain"),
name = fct_reorder(name, worth)
)
wealth_plot <- wealth %>%
mutate(original = round(worth / (increase + 1), digits = 1),
increase = worth-original,
decrease = pmin(increase,0),
increase = pmax(increase,0),
original = original+decrease,
decrease = -decrease) %>%
select(name, font_face_bold, original, increase,decrease) %>%
gather(key="type", value="value", -name, -font_face_bold) %>%
ggplot(aes(y=name,weight=value,fill=type))+
geom_bar()+
scale_fill_manual(values = c( "#DDC7CC", "#97D27B", "#24598f")) +
scale_x_continuous(
labels = scales::comma,
position = "top",
breaks = c(0, 50, 100, 150, 200)) +
coord_cartesian(clip = "off", xlim = c(1,220)) +
theme_minimal() +
theme(
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_line(color = "#787878"),
legend.position = "none",
plot.title = element_text(face = "bold"),
axis.text.y = element_text(
size = 16,
),
axis.text.x = element_text(size = 12, face = "bold", color = "#787878"),
plot.background = element_rect(fill = "#fdf0e5"),
plot.caption = element_text(hjust = 0),
plot.subtitle = element_text(color = "#787878"),
plot.caption.position = "plot",
plot.title.position = "plot"
) +
labs(
x = "", y = "", title = "Tesla bump puts Musk into top ten wealthiest individuals",
subtitle = "Bar length is 2020 vs 2019",
caption = "\nAs of July 13 2020\nSource: Bloomberg\n@thomas_mock & @skyetetra"
)
wealth_plot
ggsave("wealth_plot.png", wealth_plot, height = 6, width = 10, units = "in", dpi = "retina")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment