library(tidyverse)

Exercise 1: Customized scatter plot

You will try to recreate a plot from an Economist article showing the relationship between well-being and financial inclusion.

You can find the accompanying article at this link

The data for the exercises EconomistData.csv can be downloaded from the class github repository.

url <- paste0("https://raw.githubusercontent.com/cme195/cme195.github.io/",
              "master/assets/data/EconomistData.csv")
dat <- read_csv(url)
Parsed with column specification:
cols(
  Country = col_character(),
  SEDA.Current.level = col_double(),
  SEDA.Recent.progress = col_double(),
  Wealth.to.well.being.coefficient = col_double(),
  Growth.to.well.being.coefficient = col_double(),
  Percent.of.15plus.with.bank.account = col_double(),
  EPI_regions = col_character(),
  Region = col_character()
)
head(dat)
  1. Create a scatter plot similar to the one in the article, where the x axis corresponds to percent of people over the age of 15 with a bank account (the Percent.of.15plus.with.bank.account column) and the y axis corresponds to the current SEDA score SEDA.Current.level.
  2. Color all points blue.
  3. Color points according to the Region variable.
  4. Overlay a fitted smoothing trend on top of the scatter plot. Try to change the span argument in geom_smooth to a low value and see what happens.
  5. Overlay a regression line on top of the scatter plot Hint: use geom_smooth with an appropriate method argument.
  6. Facet the previous plot by Region.

Exercise 2: Distribution of categorical variables

  1. Generate a bar plot showing the number of countries included in the dataset from each Region.
  2. Rotate the plot so the bars are horizontal

Exercise 3: Distribution of continuous variables

  1. Create boxplots of SEDA scores, SEDA.Current.level separately for each Region.
  2. Overlay points on top of the box plots
  3. The points you added are on top of each other, in order to distinguish them jitter each point by a little bit in the horizontal direction.
  4. Now substitute your boxplot with a violin plot.
LS0tCnRpdGxlOiAiTGVjdHVyZSA0OiBFeGVyY2lzZXMiCmRhdGU6IE9jdG9iZXIgOXRoLCAyMDE4Cm91dHB1dDogCiAgaHRtbF9ub3RlYm9vazoKICAgIHRvYzogdHJ1ZQogICAgdG9jX2Zsb2F0OiB0cnVlCiAgICBkZl9wcmludDoga2FibGUKLS0tCgpgYGB7ciwgbWVzc2FnZT1GQUxTRSwgd2FybmluZz1GQUxTRX0KbGlicmFyeSh0aWR5dmVyc2UpCmBgYAoKCiMgR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