-
Notifications
You must be signed in to change notification settings - Fork 0
/
thorconPopEnergyChart.Rmd
56 lines (53 loc) · 2.57 KB
/
thorconPopEnergyChart.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
---
title: "dim2barchart"
author: "GeoffRussell"
date: "10/28/2021"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
comma<-function(x) prettyNum(signif(x,digits=3),big.mark=",")
```
```{r}
df<-tribble(
~Region,~PerCapEnergy,~Population,
"North America",1500,490,
"European Union",700,510,
"China",400,1400,
"Mid East and Nth Africa",320,420,
"Latin America & Carribbean",240,630,
"India",85,1340,
"SE Asia & Others",75,1740,
"Sub-Saharan Africa",58,1080
)
etarget<-550
df <- df %>% mutate(xmin=cumsum(Population)-Population,xmax=xmin+Population,ymin=0,ymax=PerCapEnergy)
dfepoor <- df %>% filter(!Region %in% c("North America","European Union"))
shortfall<-dfepoor %>% summarise(sum((etarget-PerCapEnergy)*Population/1000))
totalgw<-df %>% summarise(sum(PerCapEnergy*Population/1000))
dfbig <- df %>% filter(Region %in% c("North America","European Union","China","Mid East and Nth Africa","Latin America & Carribbean"))
dfsmall <- df %>% filter(!Region %in% c("North America","European Union","China","Mid East and Nth Africa","Latin America & Carribbean"))
dfr<-tribble(
~xmin,~xmax,~ymin,~ymax,
0, 7600,0,etarget
)
p<-df %>% ggplot()+
geom_rect(aes(xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax),fill="grey",data=dfr) +
geom_rect(aes(xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax,fill=reorder(Region,PerCapEnergy))) +
geom_text(aes(x=xmin+(xmax-xmin)/2,y=ymin+(ymax-ymin)/2,
label=paste0(comma(PerCapEnergy*Population/1000),"GW")),data=dfbig,angle=90,size=4,color="white") +
geom_text(aes(x=xmin+(xmax-xmin)/2,y=ymin+(ymax-ymin)/2,
label=paste0(comma(PerCapEnergy*Population/1000),"GW")),data=dfsmall,size=3) +
geom_text(aes(x=xmin+60,y=ymax+110,label=Region,hjust=0),size=2)+
geom_text(aes(x=xmin+60,y=ymax+70,label=paste0(PerCapEnergy,"w"),hjust=0),size=2)+
geom_text(aes(x=xmin+60,y=ymax+30,label=paste0(Population,"m"),hjust=0),size=2)+
annotate('text',x=1000,y=1500,label=paste0("Current Global Power: ",comma(totalgw),"GW"),hjust=0,vjust=0)+
annotate('text',x=7500,y=500,label=paste0("Developing Country Shortfall: ",comma(shortfall),"GW"),hjust=1)+
scale_fill_brewer(palette="Oranges",breaks=c("North America","European Union","China","Mid East and Nth Africa","Latin America & Carribbean","India","SE Asia & Others","Sub-Saharan Africa"))+
labs(y="Watts (continuous power) per person",x="Population",fill="Region",title="Global Electricity Shortfall (cf. Thorcon website)")
p
png(paste0("thorcon-pop-energy.png"),width=1800,height=900,units="px",res=200,type="cairo-png")
p
dev.off()
```