The data used in making this plot is the big mac index dataset on January 2014. The process in replicating the economist plot can be seen below
Load the data and investigate the data to know what are the attributes that will be used. In this case, we make two new attributes named percentage and ordercount. The precentage show the percentage of big mac price in a country towards the big mac price in United States. While, ordercount shows the countries oredered decreasingly based on the price of big mac in dollar.
bmi <- read.csv("BM data Jan 2014.csv")
names(bmi)
## [1] "Country" "local_price"
## [3] "dollar_ex" "dollar_price"
## [5] "dollar_ppp" "dollar_valuation"
## [7] "dollar_adj_valuation" "euro_adj_valuation"
## [9] "sterling_adj_valuation" "yen_adj_valuation"
## [11] "yuan_adj_valuation"
countries <- c("Norway","Switzerland","Brazil","Canada","Euro area†","Britain","United States#","Australia","Turkey","Japan","China$","Russia","Egypt","Indonesia","South Africa","India**")
bmi1 <- bmi[bmi$Country %in% countries,c(1,4)]
bmi2 <- as.data.frame(bmi1)
bmi2$percentage <- ((bmi2$dollar_price/4.62) - 1)*100
bmi2$ordercount <- factor(bmi2$Country, levels = bmi2$Country[order(bmi2$dollar_price)])
str(bmi2)
## 'data.frame': 16 obs. of 4 variables:
## $ Country : Factor w/ 57 levels "Argentina","Australia",..: 2 5 6 7 9 14 16 23 24 28 ...
## $ dollar_price: num 4.47 5.25 4.63 5.01 2.74 2.43 4.96 1.54 2.3 2.97 ...
## $ percentage : num -3.247 13.636 0.216 8.442 -40.693 ...
## $ ordercount : Factor w/ 16 levels "India**","South Africa",..: 9 14 11 13 6 4 12 1 3 7 ...
head(bmi2)
## Country dollar_price percentage ordercount
## 2 Australia 4.47 -3.2467532 Australia
## 3 Brazil 5.25 13.6363636 Brazil
## 4 Britain 4.63 0.2164502 Britain
## 5 Canada 5.01 8.4415584 Canada
## 7 China$ 2.74 -40.6926407 China$
## 12 Egypt 2.43 -47.4025974 Egypt
From 57 countries, we chosed 16 countries based on the plot in economist daily chart
library(ggplot2)
p1 <- ggplot(bmi2, aes(x = bmi2$ordercount, y = bmi2$percentage)) + geom_hline(yintercept = 0, linetype=1, color = "red", size=1) +
geom_hline(yintercept = c(-80, -40, 40, 80), linetype = 1, color = "white", size = 1)+ geom_bar(stat = "identity", width = .7, fill = "#01516c")
p1
after creating the basic plot, we draw three lines in white, then made a bar plot using geom_bar function. The order should be like that to make lines position is in behind bar plot.
p2 <- p1 + coord_flip()
p2
p3 <- p2 + theme(panel.grid.minor = element_blank(),
panel.grid.major = element_line(color = "white", size = 1),
panel.grid.major.y = element_blank(),
panel.background = element_blank(),
line = element_blank()) + ggtitle ("The Big Mac Index\n") + labs(subtitle = "local currency under (-)/over (+) valuation\nagainst the dollar, %") + labs(caption = "*At market exchange rates(Jan 22nd 2014)\nWeighted average of member countries\n#Average of four cities $Average of five cities\nSources: McDonald's; The Economist **Maharaja Mac")
p3
p4 <- p3 + theme(plot.title = element_text(hjust = -0.15, vjust=2.12, colour="black", size = 14,
face="bold"), plot.subtitle = element_text(hjust = -0.15, vjust = 1.92,
colour = "black", size = 12))
p4
library(ggthemes)
p5 <- p4 + theme_economist() +
scale_color_economist() + scale_y_discrete(expand = c(0,8), position = "right", breaks = seq(-80,80,40), lim = c(-80,-40,0,40,80))
p5
As we can see, we adjust the fig.height and fight.width in the chunk. Those codes can make a figure generated more fit the plot
#-----------------
p6 <- p5 + theme(axis.title.x=element_blank(), axis.title.y = element_blank(), axis.ticks.x=element_blank(), line = element_blank() + annotate("text", label = "nil", x = 10, y = 3)) + annotate("text", label = "nil", x = 10, y = 3) + annotate("text", label ="0.1", x = 11, y = 5)
#-------------------
p6
p7 <- p6 + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.line.x.top = element_blank())
p7
In this step, we use annotate(“label”, …) to make the value box in the right side.
p8 <- p7 + annotate("label", x = bmi2$ordercount, y = max(bmi2$percentage)+25, label = bmi2$dollar_price, col = "black")
p8
Yet, several value box formatted in 1 decimal, later, the author will revise it soon.
p9 <- p8 + expand_limits(y = c(-80, 85)) + theme(axis.text.x = element_text(vjust = 1))
p9
Still, there are some limitation that can be improved in replicating the economist plot. The author will revised it soon when finding the right code to improve the plot.