Task

Using the gapminder dataset:

  1. Do one visualization.

  2. Show and interpret one descriptive statistic (insert text on bottom of code).

  3. Print the phrase: I did it!

since gapminder is such a big dataset, I will portray only European countries in the year 2002

gapminder_europe2002 <- filter(gapminder, continent == "Europe", year == 2002)

Visualization

I am going to visualize the relationship between the independent variable “GDP per Capita” and the dependent variable “Life Expectancy” in my filtered gapminder dataset

ggplot(gapminder_europe2002,
       mapping = aes(x = gdpPercap, 
                     y = lifeExp)) + 
  geom_point() + 
  geom_smooth() + 
  labs(x = "GDP per Capita", 
       y = "Life Expectancy (in years)", 
       title = "GDP and Life Expectancy",
       subtitle = "Among European Countries in 2002")
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

Descriptive Statistic

Albania’s life expectancy was 75.61 in 2002, is that good or bad? We need some number to compare this to, so, lets find the median life expectancy of European countries in 2002. Since there are clearly some outliers in our scatter plot, median would be a better measure of central tendency than, for example, mean as it is unaffected by outliers

median(gapminder_europe2002$lifeExp)
## [1] 77.5365

We can see the median life expectancy is approximately 77.54. This means that Albania is slightly below average when it comes to life expectancy, but certainly closer to the average than European countries like Bulgaria (life expectancy of 72.14).

Further, if we find the median life expectancy for the other continents, we can now make comparisons and interpretations among continents.

gapminder_africa2002 <- filter(gapminder, continent == "Africa", year == 2002)
median(gapminder_africa2002$lifeExp)
## [1] 51.2355

In 2002, Europe had a way higher life expectancy than Africa (77.54 vs 51.24). Albania then has a higher life expectancy than the average African country but lower than the average European country. One could interpret this such that one would likely live a longer life if they lived in Albania than if they lived in an African country

Printing “I did it!”

print("I did it!")
## [1] "I did it!"