assignment 5 - colton

Top 15 Cities: Population & Map Analysis

1. Intro

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 libraries
library(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 population
plot_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)
  )
# Leaflet interactive map
leaflet(cities) |>
  addTiles() |>
  addCircleMarkers(
    lat = ~lat,
    lng = ~lon,
    radius = ~sqrt(pop) / 1000,
    fillColor = "dodgerblue",
    color = NULL,
    fillOpacity = 0.6,
    popup = ~paste0(
      "<strong>", city, ", ", country, "</strong><br>",
      "Population: ", format(pop, big.mark = ",")
    )
  ) |>
  setView(lng = 0, lat = 20, zoom = 2)

2. Bar Chart (Plotly)

A. Visualization

An interactive bar chart shows population sizes. Hover shows extra info like city, country, and exact numbers.

B. Reflection

  • Patterns: Tokyo is biggest. Asia dominates.

  • Why this chart: Horizontal bars are easy to read, and tooltips add good context.

  • Does it work: Yep. It’s clear and simple.

3. Map (Leaflet)

A. Visualization

Each city is a circle on a map. Bigger circles = more people. Clicking shows name and population.

B. Reflection

  • Patterns: Cities mostly in Asia and near coasts.

  • Why this style: Circles are easy to see. Blue pops well.

  • Does it work: Yes. Simple and mobile-friendly.

  • Self-rating: 9/10. It’s clean and on target.

4. Conclusion

The chart shows who’s biggest. The map shows where they are. Together, they give a full picture.

What’s next:

  • Add more cities

  • Compare GDP or density

  • Try regions like just Asia or Latin America

Tech note: No big problems. Just needed a basic clean CSV. Could go deeper with more data.