This is my attempt to duplicate this economist plot plot.
library (ggplot2)
library(ggrepel)
rgdp <- read.csv("C:/Users/fafiliam/Documents/gdp_world.csv",header = TRUE)
str(rgdp)
## 'data.frame': 55 obs. of 6 variables:
## $ years : int 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 ...
## $ japan : num 7.21 7.2 7.22 7.74 8.14 8.01 8.23 8.87 9.56 9.95 ...
## $ italy : num 5.19 5.23 5.57 5.25 5.19 4.98 5.2 5.25 5.19 5.17 ...
## $ france : num 3.97 3.98 4 4.02 4.03 4.01 4 4.34 4.57 4.26 ...
## $ us : num 1.91 1.02 1.18 1.21 2.02 2.03 2.48 2.53 3.23 3.59 ...
## $ germany: num NA NA NA NA NA NA NA NA NA NA ...
rgdp_plot <- ggplot(rgdp, aes(x=years)) +
geom_line(aes(y=france),size = 1.5,color="#608a99")+
geom_line(aes(y=italy),size =1.5,color="#71d0f2") +
geom_line(aes(y=germany),size = 1.5,color="#878e8e")+
geom_line(aes(y=japan),size = 1.5,color="#55d1b8") +
geom_line(aes(y=us),size = 1.5,color="#1a323a")
rgdp_plot
## Warning: Removed 11 rows containing missing values (geom_path).
plotgdp <- rgdp_plot+
geom_text(aes(y=rgdp$france[10]-0.5,x=rgdp$years[3],label="France"),color="black", alpha=0.1)+
geom_text(aes(y=rgdp$italy[2]+0.5,x=rgdp$years[5],label="Italy"),color="black", alpha=0.1)+
geom_text(aes(y=rgdp$germany[40]+1.5,x=rgdp$years[53]+1,label="Germany"),color="black", alpha=0.1)+
geom_text(aes(y=rgdp$japan[15],x=rgdp$years[20],label="Japan"),color="black", alpha=0.1)+
geom_text(aes(y=rgdp$us[4]-0.5,x=rgdp$years[4]+1,label="United States"),color="black", alpha=0.1)
plotgdp
## Warning: Removed 11 rows containing missing values (geom_path).
plotgdp2 <- plotgdp + labs(title="Real GDP",subtitle="% change on earlier year\n Ten years moving average",caption = "Source: Pen Table World; The Economist")
plotgdp2
## Warning: Removed 11 rows containing missing values (geom_path).
library(ggthemes)
plotgdp3 <- plotgdp2 +
geom_hline(yintercept =0 , colour="red")+
scale_x_continuous(breaks = seq(1960,2014,1), label=c("1960"," "," "," "," "," "," "," "," "," ",
"70"," "," "," "," "," "," "," "," "," ",
"80"," "," "," "," "," "," "," "," "," ",
"90"," "," "," "," "," "," "," "," "," ",
"2000"," "," "," "," "," "," "," "," "," ",
"10"," "," "," ","2014"))+
scale_y_continuous(position= "right", limits= c(-2,10),breaks = seq(-2,10,2))+
theme_economist_white(gray_bg = FALSE) +
scale_colour_economist()+
theme(axis.title.x=element_blank(),
axis.title.y=element_blank(),
axis.ticks.length = unit(.15,"cm"),
axis.text.y.right = element_text(margin = margin(t=0,b=0,r=0,l=10)),
plot.caption=element_text(hjust = 0))
plotgdp3
## Warning: Removed 11 rows containing missing values (geom_path).