R Tutorial: The gapminder dataset

Dave Robinson teaches R data exploration using the gapminder dataset, a collection of 1,704 country observations with life expectancy, population, and GDP per capita over time. You'll learn to load packages with library(), extract insights like Afghanistan's trends, and build visualizations with ggplot2.
Chapters
Hi, I'm Dave Robinson and I'll be your instructor. I'm a data scientist and I love using R to dive into a data set and discover interesting things. This course will get you started on the path to exploring and visualizing your own data with the R programming language. This course introduces you to the tidyverse, a collection of data science tools within R for transforming and visualizing data. This is not the only set of tools in R, but it's a powerful and popular approach for exploring data. At every step you'll be analyzing a real data set called gapminder. Gapminder tracks economic and social indicators like life expectancy and the GDP per capita of countries over time. The experience you gain on this example will help you in analyzing your own data. You'll learn to draw specific insights and communicate them through informative visualizations with the ggplot2 package. This course is interactive between the short videos. You'll complete exercises by typing in code with help from us along the way. The first code you'll write is to load two R packages, which is done by writing library parentheses, the name of the package, then end parentheses. R packages are tools that aren't built into the language but were created later by other programmers. Each of them provides tools that you don't have to write yourself. The first package is gapminder, created by Jenny Bryan, which contains the data set that you'll be analyzing. The second package is dplyr, created by Hadley Wickham, which provides step by step tools for transforming this data, such as filtering, sorting, and summarizing it. You type gapminder to display the contents of the gapminder object, which is structured as a data frame. A data frame keeps rectangular data in rows and columns, similar to a spreadsheet or a table in a SQL database. Most data analyses in R and everything you'll do in this course are centered around data frames as described in the first line of the output. This is a special type of data frame called a tibble, though for now you don't have to worry about the difference. R displays the first 10 rows so that you can get a glimpse of it and you can see a short description in the first line. This tells you that the tibble has 1704 rows, each of which we call an observation. It has six columns and each of which we call a variable. It's important in an analysis to understand what each observation or row represents. Here, each represents a unique pair of a country and a year. For example, the first observation represents country statistics for Afghanistan in 1952 the second for Afghanistan in 1957 and so on. For each combination of a country and year, the dataset contains several variables or columns describing the country's demographics. We see the continent, in this case Asia, the life expectancy in years, the population and the GDP per capita. The GDP per capita is the country's total economic output gross domestic product divided by its population, and it's a common measure of how wealthy a country is. Each variable is of one consistent data type. Some are numbers like life expectancy and population and some are categorical like country and continent. Even with this small glimpse of the data you can extract a few insights. For example, you can see that Afghanistan's life expectancy and population have both gone up from 1952 to 1997, but that its GDP per capita has wavered. In the rest of this course you'll learn to use R to draw many conclusions about the social and economic history of countries around the world.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







