This project uses a simple dataset of 15 of the world’s biggest cities by population. It includes each city’s name, country, location (lat/lon), and total population. I chose this data because it’s clean, clear, and good for making both map and chart visuals.
What I looked at:
Population differences (bar chart)
Where cities are located (map)
Source: Self-made CSV from public population stats (Wikipedia, etc.)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.0.4
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(plotly)
Warning: package 'plotly' was built under R version 4.4.3
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
library(leaflet)
Warning: package 'leaflet' was built under R version 4.4.3
# Load librarieslibrary(tidyverse)library(plotly)library(leaflet)# Load dataset (make sure the CSV is in your project folder)cities <-read_csv("fifteen_cities.csv")# Plotly bar chart of top 15 cities by populationplot_ly(data = cities,x =~pop,y =~reorder(city, pop),type ="bar",orientation ="h",text =~paste0(city, ", ", country, "<br>Pop: ", format(pop, big.mark =",")),hoverinfo ="text",marker =list(color ="orange")) |>layout(title ="Top 15 Most Populous Cities",xaxis =list(title ="Population"),yaxis =list(title =""),margin =list(l =100) )