June 22, 2025
readr for reading datatidyr for data tidyingdplyr for data manipulationggplot2 for data visualizationlibrary(ggplot2)library(tidyverse)::, e.g. ggplot2::ggplot()readr package to read in a datasetOne way to do this is with the base R head() function
# A tibble: 6 × 5
region polyarchy gdp_pc flfp women_rep
<chr> <dbl> <dbl> <dbl> <dbl>
1 The West 0.871 37.9 53.0 28.1
2 Latin America 0.637 9.61 48.1 21.3
3 Eastern Europe 0.539 12.2 50.5 18.0
4 Asia 0.408 9.75 50.3 14.5
5 Africa 0.393 4.41 56.7 17.4
6 Middle East 0.246 21.1 26.6 10.2
View()Another way to look at the data is with View(). Or click on the name of the data frame in the Environment pane.
glimpse() from dplyrAnother way to look at the data is with glimpse() from the dplyr package.
Rows: 6
Columns: 5
$ region <chr> "The West", "Latin America", "Eastern Europe", "Asia", "Afri…
$ polyarchy <dbl> 0.8709230, 0.6371358, 0.5387451, 0.4076602, 0.3934166, 0.245…
$ gdp_pc <dbl> 37.913054, 9.610284, 12.176554, 9.746391, 4.410484, 21.134319
$ flfp <dbl> 52.99082, 48.12645, 50.45894, 50.32171, 56.69530, 26.57872
$ women_rep <dbl> 28.12921, 21.32548, 17.99728, 14.45225, 17.44296, 10.21568
dem_summary.csv file05:00
dplyr FunctionsUse select() to choose columns.
dplyr FunctionsUse filter() to choose rows.
Rows: 3
Columns: 5
$ region <chr> "The West", "Eastern Europe", "Middle East"
$ polyarchy <dbl> 0.8709230, 0.5387451, 0.2458892
$ gdp_pc <dbl> 37.91305, 12.17655, 21.13432
$ flfp <dbl> 52.99082, 50.45894, 26.57872
$ women_rep <dbl> 28.12921, 17.99728, 10.21568
Note
Using the same name for the data frame results in overwriting the original data frame. If you want to keep the original data frame, use a different name.
dplyr FunctionsUse mutate() to create new columns.
dem_summary_abbr <- dem_summary |>
mutate(gdp_pc_thousands = gdp_pc * 1000)
glimpse(dem_summary_abbr)Rows: 6
Columns: 6
$ region <chr> "The West", "Latin America", "Eastern Europe", "Asia"…
$ polyarchy <dbl> 0.8709230, 0.6371358, 0.5387451, 0.4076602, 0.3934166…
$ gdp_pc <dbl> 37.913054, 9.610284, 12.176554, 9.746391, 4.410484, 2…
$ flfp <dbl> 52.99082, 48.12645, 50.45894, 50.32171, 56.69530, 26.…
$ women_rep <dbl> 28.12921, 21.32548, 17.99728, 14.45225, 17.44296, 10.…
$ gdp_pc_thousands <dbl> 37913.054, 9610.284, 12176.554, 9746.391, 4410.484, 2…
dplyr verbs to manipulate the data05:00
ggplot2ggplot2 is a powerful data visualization packageggplot2ggplot2 to make a simple column chart05:00