
Tidy Tuesday: Shanghai has 451 hospitals and no pharmacies, according to this map
Preface
From the TidyTuesday repository.
This week we’re exploring the Global Human Settlement Urban Centre Database Produced by the Joint Research Centre (JRC) of the European Commission, part of the Copernicus Emergency Management Service. These are open and free data and tools to assess the human presence on the planet. The dataset covers more than 10,000 urban centres worldwide, each delineated using a population density, size, and grid-cell contiguity method called the Degree of Urbanisation. Here, we are specifically looking at the Health component which details information regarding hospitals and pharmacies in urban centers.
Gabriela Palomo-Munoz curated this one, and the first suggested question asks which city or country has the most hospitals and pharmacies per capita. I started down that road and stopped fast. Shanghai, a city of about 31 million people, has no pharmacy count in this file. Neither does Istanbul or Cairo. Mumbai has four. Once I looked at which cities do have a pharmacy number, it was clear the pharmacy column says more about how well each country’s facilities have been mapped than about how many pharmacies it has.
Loading necessary packages
Code
library(tidyverse)
library(tidytuesdayR)
library(skimr)
library(scales)
library(paletteer)
`%ni%` <- Negate(`%in%`)
lancet <- as.character(paletteer::paletteer_d("ggsci::lanonc_lancet"))
hospital_col <- lancet[1]
pharmacy_col <- lancet[2]
ink <- lancet[9]
fog <- lancet[8]
paper <- "#F7F8F8"Load raw data from package
raw <- tidytuesdayR::tt_load("2026-09-29")
health <- raw$healthExploratory data analysis
The column names are the GHSL codes, so I’m giving them short names first. I’m dropping the ID and the city name from the skim, since neither is useful to summarize.
centres <- health %>%
transmute(
id = ID_UC_G0,
city = GC_UCN_MAI_2025,
country = GC_CNT_GAD_2025,
area_km2 = GC_UCA_KM2_2025,
pop = GC_POP_TOT_2025,
income = GC_DEV_WIG_2025,
region = GC_DEV_USR_2025,
hospitals = HL_FCL_HOS_2024,
pharmacies = HL_FCL_PHA_2024,
share_near_hospital = HL_SHP_HOS_2025,
share_near_pharmacy = HL_SHP_PHA_2025
)
centres %>%
select(-id, -city) %>%
skim()| Name | Piped data |
| Number of rows | 11422 |
| Number of columns | 9 |
| _______________________ | |
| Column type frequency: | |
| character | 3 |
| numeric | 6 |
| ________________________ | |
| Group variables | None |
Variable type: character
| skim_variable | n_missing | complete_rate | min | max | empty | n_unique | whitespace |
|---|---|---|---|---|---|---|---|
| country | 0 | 1 | 4 | 32 | 0 | 191 | 0 |
| income | 9 | 1 | 10 | 12 | 0 | 4 | 0 |
| region | 0 | 1 | 6 | 32 | 0 | 9 | 0 |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| area_km2 | 0 | 1.00 | 56.82 | 185.05 | 1.00 | 13.00 | 23.00 | 44.00 | 6611.00 | ▇▁▁▁▁ |
| pop | 0 | 1.00 | 322653.88 | 1315392.63 | 50007.75 | 69478.66 | 104136.12 | 204771.26 | 42987704.03 | ▇▁▁▁▁ |
| hospitals | 5185 | 0.55 | 15.47 | 42.88 | 2.00 | 2.00 | 6.00 | 12.00 | 1016.00 | ▇▁▁▁▁ |
| pharmacies | 9026 | 0.21 | 18.06 | 56.29 | 2.00 | 2.00 | 6.00 | 14.00 | 1096.00 | ▇▁▁▁▁ |
| share_near_hospital | 4988 | 0.56 | 34.31 | 20.84 | 0.00 | 17.96 | 31.53 | 47.67 | 100.00 | ▆▇▆▂▁ |
| share_near_pharmacy | 8952 | 0.22 | 24.13 | 19.05 | 0.00 | 9.73 | 19.08 | 33.75 | 98.87 | ▇▅▂▁▁ |
centres %>%
count(income)# A tibble: 5 × 2
income n
<chr> <int>
1 High income 1593
2 Low income 1050
3 Lower Middle 4591
4 Upper Middle 4179
5 <NA> 9
The thing that jumps out is the missingness. Out of 11,422 urban centres, 5,185 have no hospital count and 9,026 have no pharmacy count. That’s 79% of the file with no pharmacy number at all.
The counts are odd in another way, too. The smallest count in either column is 2, never 0 or 1, and most counts are even:
centres %>%
pivot_longer(c(hospitals, pharmacies), names_to = "facility", values_to = "n") %>%
filter(!is.na(n)) %>%
group_by(facility) %>%
summarise(
centres_with_count = n(),
smallest = min(n),
even_counts = mean(n %% 2 == 0)
)# A tibble: 2 × 4
facility centres_with_count smallest even_counts
<chr> <int> <dbl> <dbl>
1 hospitals 6237 2 0.947
2 pharmacies 2396 2 0.972
The data dictionary doesn’t explain this. My guess is that a missing value here means “nothing was found,” not “no one checked,” since a city with zero facilities would otherwise show up as 0 somewhere. I can’t confirm it from the metadata, though, so I’m calling these cities “no pharmacy recorded” and not “no pharmacies.”
Where the pharmacies are missing
If missing pharmacy counts were mostly a small-town problem, I’d expect them to disappear in the biggest cities. They don’t.
missing_by_size <- centres %>%
mutate(
size_band = cut(
pop,
breaks = c(0, 1e5, 2.5e5, 1e6, 5e6, Inf),
labels = c("50k-100k", "100k-250k", "250k-1M", "1M-5M", "Over 5M")
)
) %>%
group_by(size_band) %>%
summarise(
centres = n(),
no_hospital = mean(is.na(hospitals)),
no_pharmacy = mean(is.na(pharmacies))
)
missing_by_size# A tibble: 5 × 4
size_band centres no_hospital no_pharmacy
<fct> <int> <dbl> <dbl>
1 50k-100k 5478 0.569 0.859
2 100k-250k 3660 0.446 0.8
3 250k-1M 1760 0.235 0.668
4 1M-5M 437 0.0412 0.442
5 Over 5M 87 0 0.253
megacities <- centres %>%
filter(pop > 5e6)
mega_no_pharmacy <- megacities %>%
filter(is.na(pharmacies)) %>%
arrange(desc(pop))
shanghai <- centres %>%
filter(city == "Shanghai")
stopifnot(nrow(shanghai) == 1, nrow(mega_no_pharmacy) > 0)Every one of the 87 urban centres over five million people has a hospital count. 22 of them have no pharmacy count, and 11 of those are in China: Shanghai, Suzhou, Nanjing, Hangzhou, Chengdu, Chongqing, and more. Shanghai has 451 hospitals recorded and no pharmacies. Turkey and Egypt look the same. Istanbul has 584 hospitals and no pharmacy count. Cairo has 200 hospitals and none either.
Those aren’t cities without pharmacies. They’re cities where this source didn’t pick any up. So the next step is to look at coverage by country.
income_levels <- c("High income", "Upper Middle", "Lower Middle", "Low income")
country_coverage <- centres %>%
filter(!is.na(income)) %>%
group_by(country, income) %>%
summarise(
centres = n(),
with_hospital = mean(!is.na(hospitals)),
with_pharmacy = mean(!is.na(pharmacies)),
.groups = "drop"
) %>%
filter(centres >= 50) %>%
mutate(
income = factor(income, levels = income_levels),
country = fct_reorder(country, with_pharmacy)
)
cat(sprintf("country_coverage: %d rows, %d cols\n", nrow(country_coverage), ncol(country_coverage)))country_coverage: 42 rows, 5 cols
stopifnot("Plot data has 0 rows — check filter values" = nrow(country_coverage) > 0)
stopifnot("Income levels didn't match" = !anyNA(country_coverage$income))
country_coverage %>%
arrange(desc(with_pharmacy)) %>%
mutate(across(starts_with("with_"), ~ percent(.x, accuracy = 1))) %>%
print(n = Inf)# A tibble: 42 × 5
country income centres with_hospital with_pharmacy
<fct> <fct> <int> <chr> <chr>
1 France High in… 73 99% 93%
2 Japan High in… 135 87% 90%
3 United Kingdom High in… 143 94% 85%
4 Canada High in… 54 83% 85%
5 United States High in… 344 89% 81%
6 Ukraine Lower M… 75 99% 65%
7 Germany High in… 99 95% 63%
8 Russia Upper M… 253 97% 60%
9 Argentina Upper M… 77 94% 58%
10 Poland High in… 63 95% 56%
11 Brazil Upper M… 366 86% 54%
12 Philippines Lower M… 117 88% 49%
13 México Upper M… 182 81% 47%
14 Venezuela Upper M… 70 74% 44%
15 Colombia Upper M… 83 77% 41%
16 Italy High in… 88 93% 40%
17 Indonesia Upper M… 369 57% 28%
18 Uzbekistan Lower M… 72 68% 28%
19 Thailand Upper M… 54 70% 26%
20 Spain High in… 85 92% 25%
21 Iran Lower M… 169 86% 22%
22 Algeria Lower M… 109 93% 19%
23 Bangladesh Lower M… 239 29% 14%
24 Morocco Lower M… 72 68% 12%
25 South Africa Upper M… 81 77% 11%
26 Iraq Upper M… 86 49% 10%
27 Ghana Lower M… 53 77% 9%
28 Angola Lower M… 56 38% 7%
29 Vietnam Lower M… 128 77% 6%
30 Democratic Republic of the Congo Low inc… 189 27% 3%
31 India Lower M… 1925 22% 3%
32 Myanmar Lower M… 113 39% 3%
33 Sudan Low inc… 80 29% 2%
34 Pakistan Lower M… 299 27% 2%
35 Nigeria Lower M… 425 26% 2%
36 Ethiopia Low inc… 184 31% 2%
37 Afghanistan Low inc… 74 19% 1%
38 China Upper M… 1974 45% 1%
39 Turkey Upper M… 174 81% 1%
40 Egypt Lower M… 214 17% 0%
41 North Korea Low inc… 92 12% 0%
42 Yemen Low inc… 58 26% 0%
overall_pharmacy <- mean(!is.na(centres$pharmacies))These are the 42 countries with at least 50 urban centres. In France, 93% of urban centres have a pharmacy count. In Japan it’s 90%. In China it’s 1%, across 1,974 urban centres. Hospital coverage varies too, but it’s higher than pharmacy coverage almost everywhere. Japan and Canada are the only exceptions. The biggest gap is Turkey: 81% of its urban centres have a hospital count and 1% have a pharmacy count.
coverage_long <- country_coverage %>%
pivot_longer(
c(with_hospital, with_pharmacy),
names_to = "facility",
values_to = "share"
) %>%
mutate(facility = recode(facility, with_hospital = "Hospital", with_pharmacy = "Pharmacy"))
stopifnot(nrow(coverage_long) == 2 * nrow(country_coverage))
key_labels <- coverage_long %>%
filter(country == "Russia") %>%
mutate(label = if_else(facility == "Hospital", "hospital count", "pharmacy count"))
china <- country_coverage %>%
filter(country == "China")
# The China segment ends at its hospital share, so the note starts just past it
china_note <- tibble(
income = factor("Upper Middle", levels = income_levels),
x = china$with_hospital + 0.03,
y = "China",
label = sprintf("Shanghai: %d hospitals, no pharmacies recorded", shanghai$hospitals)
)
overall_note <- tibble(
income = factor("Low income", levels = income_levels),
x = overall_pharmacy,
y = "North Korea",
label = sprintf("All urban centres: %s have a pharmacy count", percent(overall_pharmacy, accuracy = 1))
)
p <- ggplot(country_coverage, aes(y = country)) +
geom_vline(xintercept = overall_pharmacy, linetype = "22", color = ink, linewidth = 0.4) +
geom_segment(
aes(x = with_pharmacy, xend = with_hospital, yend = country),
color = fog, linewidth = 1.1
) +
geom_point(
data = coverage_long,
aes(x = share, color = facility),
size = 2.8
) +
geom_text(
data = key_labels,
aes(x = share, label = label, color = facility),
vjust = -1, size = 3, fontface = "bold"
) +
geom_text(
data = china_note,
aes(x = x, y = y, label = label),
hjust = 0, vjust = 0.5, size = 3.1, color = pharmacy_col, fontface = "italic"
) +
geom_text(
data = overall_note,
aes(x = x, y = y, label = label),
hjust = 0, nudge_x = 0.01, vjust = 0.5, size = 3, color = ink
) +
scale_color_manual(values = c(Hospital = hospital_col, Pharmacy = pharmacy_col), guide = "none") +
scale_x_continuous(
labels = label_percent(),
breaks = seq(0, 1, 0.25),
limits = c(0, 1),
expand = expansion(mult = c(0.01, 0.02))
) +
facet_grid(income ~ ., scales = "free_y", space = "free_y", switch = "y") +
coord_cartesian(clip = "off") +
labs(
title = "Whether a city has a pharmacy count depends on its country",
subtitle = "Share of urban centres with at least one hospital or pharmacy recorded in the 2024 counts",
x = "Share of the country's urban centres with a count",
y = NULL,
caption = "Data: GHS Urban Centre Database R2024A, health theme (European Commission JRC), via TidyTuesday 2026-09-29.\nCountries with at least 50 urban centres. Income groups are the World Bank groups carried in the file."
) +
theme_minimal(base_size = 12) +
theme(
plot.background = element_rect(fill = paper, color = NA),
panel.background = element_rect(fill = "white", color = NA),
panel.grid.minor = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.major.x = element_line(color = "grey88", linewidth = 0.3),
panel.spacing.y = unit(0.9, "lines"),
strip.placement = "outside",
strip.text.y.left = element_text(angle = 0, hjust = 1, vjust = 1, face = "bold", color = ink, size = 10),
axis.text.y = element_text(color = "grey25", size = 9.5),
axis.text.x = element_text(color = "grey35"),
axis.title.x = element_text(color = "grey30", size = 10, hjust = 0, margin = margin(t = 8)),
plot.title = element_text(face = "bold", size = 18, color = ink),
plot.subtitle = element_text(color = "grey30", size = 10.5, margin = margin(b = 12)),
plot.caption = element_text(color = "grey45", hjust = 0, size = 8.5, lineheight = 1.1),
plot.title.position = "plot",
plot.caption.position = "plot",
plot.margin = margin(14, 18, 10, 10)
)
p
Read the red dots from top to bottom inside each income group. The high-income countries mostly sit on the right, but not all of them: Spain and Italy are well below Brazil and Russia. Ukraine, a lower-middle income country in this file, has better pharmacy coverage than Germany. And China, an upper-middle income country with plenty of pharmacies, has the same pharmacy coverage as Egypt, North Korea, and Yemen: next to none.
This matters for the suggested income question. Here’s the median pharmacies per 100,000 people by income group, using only the cities that have a count:
centres %>%
filter(!is.na(income)) %>%
mutate(income = factor(income, levels = income_levels)) %>%
group_by(income) %>%
summarise(
centres = n(),
with_pharmacy = percent(mean(!is.na(pharmacies)), accuracy = 1),
median_pharmacies_per_100k = median(pharmacies / pop * 1e5, na.rm = TRUE)
)# A tibble: 4 × 4
income centres with_pharmacy median_pharmacies_per_100k
<fct> <int> <chr> <dbl>
1 High income 1593 64% 4.02
2 Upper Middle 4179 21% 3.09
3 Lower Middle 4591 10% 1.85
4 Low income 1050 4% 0.688
The median rises with income. But in low-income countries that median comes from the few cities with any pharmacy recorded, and in high-income countries from most of them. Those aren’t comparable groups.
Final thoughts and takeaways
I wouldn’t use the pharmacy column to rank cities or countries. It works as a map of where pharmacies have been recorded, and that map follows national data coverage more than wealth, size, or anything about health care. France and Japan are nearly complete. China, Turkey, and Egypt are nearly empty, even in cities of 14 to 31 million people.
The hospital column is in better shape. Every urban centre over five million has a count. But it has the same problem at a smaller scale: 57% of centres under 100,000 people have no hospital count, against 3% of centres over a million. A per-capita hospital ranking would quietly drop more than half of the small cities before it started.
The caveats are mostly about what I don’t know. The TidyTuesday metadata says the database draws on “a variety of open source datasets” and doesn’t say which ones feed the facility counts, so I can’t tell you why China’s pharmacies are missing, only that they are. I also don’t know why the counts start at 2 and are mostly even. If someone knows the GHSL facility method, I’d like to hear it. Until then, the honest answer to “which city has the most pharmacies per capita” is “whichever one got mapped best.”