world_pop | R Documentation |
From World Bank, population 1960-2020
world_pop
A data frame with 216 rows and 62 variables.
Name of country.
population in 1960.
population in 1961.
population in 1962.
population in 1963.
population in 1964.
population in 1965.
population in 1966.
population in 1967.
population in 1968.
population in 1969.
population in 1970.
population in 1971.
population in 1972.
population in 1973.
population in 1974.
population in 1975.
population in 1976.
population in 1977.
population in 1978.
population in 1979.
population in 1980.
population in 1981.
population in 1982.
population in 1983.
population in 1984.
population in 1985.
population in 1986.
population in 1987.
population in 1988.
population in 1989.
population in 1990.
population in 1991.
population in 1992.
population in 1993.
population in 1994.
population in 1995.
population in 1996.
population in 1997.
population in 1998.
population in 1999.
population in 2000.
population in 2001.
population in 2002.
population in 2003.
population in 2004.
population in 2005.
population in 2006.
population in 2007.
population in 2008.
population in 2009.
population in 2010.
population in 2011.
population in 2012.
population in 2013.
population in 2014.
population in 2015.
population in 2016.
population in 2017.
population in 2018.
population in 2019.
population in 2020.
library(dplyr)
library(ggplot2)
library(tidyr)
# List percentage of population change from 1960 to 2020
world_pop |>
mutate(percent_change = round((year_2020 - year_1960) / year_2020 * 100, 2)) |>
mutate(rank_pop_change = round(rank(-percent_change)), 0) |>
select(rank_pop_change, country, percent_change) |>
arrange(rank_pop_change)
# Graph population in millions by decade for specified countries
world_pop |>
select(
country, year_1960, year_1970, year_1980, year_1990,
year_2000, year_2010, year_2020
) |>
filter(country %in% c("China", "India", "United States")) |>
pivot_longer(
cols = c(year_1960, year_1970, year_1980, year_1990, year_2000, year_2010, year_2020),
names_to = "year",
values_to = "population"
) |>
mutate(year = as.numeric(gsub("year_", "", year))) |>
ggplot(aes(year, population, color = country)) +
geom_point() +
geom_smooth(method = "loess", formula = "y ~ x") +
labs(
title = "Population",
subtitle = "by Decade",
x = "Year",
y = "Population (in millions)",
color = "Country"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.