How to make a Financial Times Plot with ggplot2 in R?
Author
Ozancan Ozdemir
Hello folks!
In this tutorial, I will illustrate how to draw a Financial Times plot with ggplot2 in R step by step. We know ggthemes package includes a theme related to Financial Times, but the theme is depreciated now.
My reference graph for this tutorial is given below.
In order to draw a plot having a similar pattern with above one, I will use only ggplot2 and ggpubr packages. Texts are from windows family. I do not import any extra fonts.
Let’s get started.
I will draw an inflation rate of Turkey. You can access the data from here.
Now, we will start to manipulate the appearance of the plot by adding title and caption.
ggplot(inflation,aes(x = Date,y = Rate))+geom_line()+labs(title ="-The Inflation rate in Turkey is at the peak of the last 17 years !",subtitle ="Starting from January 05.",caption ="FINANCIAL TIMES")
Then, change the background color, change the color and tickness of the line and remove the vertical grid lines. We will use themefunction in ggplot2 and col and sizearguments in geom_line function.
ggplot(inflation,aes(x = Date,y = Rate))+geom_line(col ="#f20656", size =1.2)+labs(title ="-The Inflation rate in Turkey is at the peak of the last 17 years !",subtitle ="Starting from January 05.",caption ="FINANCIAL TIMES")+theme(rect =element_rect(fill ="#262a33"),panel.background =element_rect(fill ="#262a33"),panel.grid.minor.x =element_blank(),panel.grid.major.x =element_blank(),panel.grid =element_line(color ="#92959e"),axis.title =element_blank())
After that, we will manipulate the texts on the plot. In other words, we will change the color and family of the texts. We will add the necessary arguments in theme function.
ggplot(inflation,aes(x = Date,y = Rate))+geom_line(col ="#f20656", size =1.2)+labs(title ="-The Inflation rate in Turkey is at the peak of the last 17 years !",subtitle ="Starting from January 05.",caption ="FINANCIAL TIMES")+theme(rect =element_rect(fill ="#262a33"),panel.background =element_rect(fill ="#262a33"),panel.grid.minor.x =element_blank(),panel.grid.major.x =element_blank(),panel.grid =element_line(color ="#92959e"),axis.title =element_blank(),plot.title =element_text(family ="Tw Cen MT", color ="white",size =18),plot.subtitle =element_text(family ="Tw Cen MT", color ="#92959e"),plot.caption =element_text(family ="Times New Roman",face ="bold",color ="#92959e"),axis.text =element_text(size =10, color ="#92959e", family ="Tw Cen MT"))
Next, we’ll put the y-axis values to the right of the graph. Also, we will paste % sign next to the values by using scale_y_continuous function.
ggplot(inflation,aes(x = Date,y = Rate))+geom_line(col ="#f20656", size =1.2)+labs(title ="-The Inflation rate in Turkey is at the peak of the last 17 years !",subtitle ="Starting from January 05.",caption ="FINANCIAL TIMES")+theme(rect =element_rect(fill ="#262a33"),panel.background =element_rect(fill ="#262a33"),panel.grid.minor.x =element_blank(),panel.grid.major.x =element_blank(),panel.grid =element_line(color ="#92959e"),axis.title =element_blank(),plot.title =element_text(family ="Tw Cen MT", color ="white",size =18),plot.subtitle =element_text(family ="Tw Cen MT", color ="#92959e"),plot.caption =element_text(family ="Times New Roman",face ="bold",color ="#92959e"),axis.text =element_text(size =10, color ="#92959e", family ="Tw Cen MT"))+scale_y_continuous(labels =function(x) paste0(x, "%"),position ="right")
Lastly, we will add the second caption on the lower left corner of the plot, which may be the hardest part of this process. For this purpose, we will use annotate_custom function. We know that the input of this function is grob object. Thus, we will consider ggpubr package to produce a grob text object. Then, we will clip off using coord_cartesian.
caption2<-ggpubr::text_grob("Source: CBRT", family ="Tw Cen MT",face ="bold", color ="#92959e", size =10)ggplot(inflation,aes(x = Date,y = Rate))+geom_line(col ="#f20656", size =1.2)+labs(title ="-The Inflation rate in Turkey is at the peak of the last 17 years !",subtitle ="Starting from January 05.",caption ="FINANCIAL TIMES")+theme(rect =element_rect(fill ="#262a33"),panel.background =element_rect(fill ="#262a33"),panel.grid.minor.x =element_blank(),panel.grid.major.x =element_blank(),panel.grid =element_line(color ="#92959e"),axis.title =element_blank(),plot.title =element_text(family ="Tw Cen MT", color ="white",size =18),plot.subtitle =element_text(family ="Tw Cen MT", color ="#92959e"),plot.caption =element_text(family ="Times New Roman",face ="bold",color ="#92959e"),axis.text =element_text(size =10, color ="#92959e", family ="Tw Cen MT"))+scale_y_continuous(labels =function(x) paste0(x, "%"),position ="right")+annotation_custom(caption2,xmin=inflation$Date[10],xmax=inflation$Date[10],ymin=-6,ymax=-6)+coord_cartesian(clip ="off")
That’s it! If you wish to use this theme as a ggplot object, you can contact me via e-mail.