This is a template file. The example included is not considered a good example to follow for Assignment 2. Remove this warning prior to submitting.

Click the Original, Code and Reconstruction tabs to read about the issues and how they were fixed.

Original


Source:The World Bank (IBRD-IRA)


Objective

The objective of this data visualization is to compare the annual inflation rate changes of USA and Sweden over time. And compare how the inflation rate has changed due to the covid pandemic. And also this visualization helps the audience to predict how the economy of USA and Sweden will behave relative to each other in future. Also this visualization gives an idea about which of these countries has the more stable economy. Target audience for this data visualization is borrowers, lenders, investors, businessmen etc. Because borrowers and lenders can use the behavior of the inflation rate to increase their profits. And investors can decide in which country are they going to invest their money in future. And businessmen can make new strategies to improve their businesses according to the inflation rate changes.

The visualization chosen had the following three main issues:

  • The lines for the both countries are of the same color. Then it is hard to identify the difference between countries.
  • This graph is drawn to analyze the annual inflation rates. But this graph shows how the inflation rates change for each and every month. Then the graph has become unclear and it is hard to see the patterns of inflation rates for each year.
  • This graph does not contain any reference lines. X axis has marked in the graph with dashed line. But it is not clearly visible. And one of the purposes of this visualization is to compare the inflation rates with covid pandemic. But there are no any reference lines to show details about covid pandemic.

Reference

Code

The following code was used to fix the issues identified in the original.

library(ggplot2)

df <- read.csv("done.csv")
p1 <- ggplot(data=df,aes(x=year,y=inflation, group=country))
p1 <- p1+  geom_line(aes(color=country), size=1)
p1 <- p1+   scale_color_manual(values=c("#5daee8","#e0db38"))
p1 <- p1+   labs(title="Inflation rates vs years", x="year",y="Inflation Rate")
p1 <- p1+   theme_classic(base_family = "serif")
p1 <- p1+   theme(aspect.ratio=9/16)
p1 <- p1+   theme(plot.title = element_text(hjust = 0.5, size=20), axis.title.y=element_text(size=15), axis.title.x=element_text(size=15))
p1 <- p1+     theme(
        legend.title = element_text(size=14),
        legend.text = element_text(size=13),
        legend.box.background = element_rect(colour = "black")) 
p1 <- p1+   scale_x_continuous(limits=c(2010,2025), breaks=scales::breaks_width((1)))
p1 <- p1+   scale_y_continuous(limits=c(-0.5,6), breaks=scales::breaks_width((0.5)))
p1 <- p1+   geom_hline(yintercept=0, linetype="solid", color = "#329629")
p1 <- p1+ geom_vline(xintercept=2020, linetype="solid", color = "red")
p1 <- p1+   geom_text(aes(2016,4,label="Before Covid Pandamic"), size=4)
p1 <- p1+   geom_text(aes(2023,4,label="After Covid Pandamic"), size=4)

Data Reference

Reconstruction

The following plot fixes the main issues in the original.