That is the second in my collection of posts about inhabitants, migration, diaspora and associated points within the Pacific. See the first publish within the collection for extra background. At the moment I’m taking a look at two charts referring to internet migration and its function in Pacific islands’ inhabitants development. These have been used early within the presentation that these weblog posts discuss with, as a part of constructing the story of the significance of individuals actions in understanding the Pacific.
These two plots are fairly simple. The information comes from the UN’s 2024 inhabitants prospects, an information supply I’ve utilized in a number of weblog posts earlier than. The actual dataset we would like is the “normal indicators”—these embrace internet migration, pure change (ie births minus deaths), and whole inhabitants for annually from 1950 to 2050; which is what we’re searching for for the charts at this time.
First downloading and wrangling the info. Fairly easy:
# attracts charts of migration and pure change affect on development
# The supply for that is UN inhabitants projections. Some particulars
# on internet migration aren't within the PDH.stat so we get them from
# the UN web site.
#
# Peter Ellis November 2025
library(tidyverse)
library(readxl)
library(scales)
#-------------Obtain and prepare the data---------------
df2 <- "pp24_standard.xlsx"
if(!file.exists(df2)){
unlink(df2)
obtain.file("https://inhabitants.un.org/wpp/property/Excelpercent20Files/1_Indicatorpercent20(Customary)/EXCEL_FILES/1_General/WPP2024_GEN_F01_DEMOGRAPHIC_INDICATORS_COMPACT.xlsx",
destfile = df2, mode = "wb")
}
un_indicators <- read_excel(df2, skip = 16)
picts <- c(
"Fiji", "New Caledonia", "Papua New Guinea", "Solomon Islands",
"Guam", "Kiribati", "Marshall Islands", "Micronesia (Fed. States of)", "Nauru",
"Vanuatu", "Northern Mariana Islands","Palau", "American Samoa", "Prepare dinner Islands",
"French Polynesia", "Niue", "Samoa", "Tokelau", "Tonga", "Tuvalu", "Wallis and Futuna Islands"
)
# verify all PICTs spelled accurately and in information
stopifnot(all(picts %in% un_indicators$`Area, subregion, nation or space *`))
pict_indicators <- un_indicators |>
rename(nation = `Area, subregion, nation or space *`) |>
filter(nation %in% picts) |>
mutate(nnm = as.numeric(`Web Variety of Migrants (1000's)`),
nmr = as.numeric(`Web Migration Fee (per 1,000 inhabitants)`) ,
nc = as.numeric(`Pure Change, Births minus Deaths (1000's)`),
laptop = as.numeric(`Inhabitants Change (1000's)`),
pop1july = as.numeric(`Whole Inhabitants, as of 1 July (1000's)`)) |>
mutate(nation = gsub("States of", "States", nation),
nation = fct_reorder(nation, abs(nmr)),
migration_direction = ifelse(nmr <0, -1, 1))
In reality, this information ‘wrangling’ isn’t rather more than filtering the info to the Pacific island nations and territories we would like; relabelling some columns for ease of use; and a little bit of twiddling with names for look’s sake within the coming graphs.
Right here’s the primary graph I needed. That is simply the web migration as a line, however to make it extra visually placing I’ve crammed within the area between the road and the net-zero horizontal axis, and colour-coded that fill with pink for unfavorable, blue for optimistic.
The important thing substantive level from this chart is the dominance of the pink—unfavorable internet migration for the Pacific, more often than not, most nations. There are fascinating tales within the blue episodes. Some are in all probability information issues that is likely to be modified later, others are associated to durations of immigration referring to development tasks. Going into every nation or territory’s explicit story right here is past the scope of my speak or the weblog, however the plot is a superb begin for anybody desirous to embark on that.
Controlling the fill like this was a bit of fiddly, and as you’ll have noticed within the earlier chunk of code, required me to make a migration_direction variable. Within the chunk under, this variable will get mapped to the fill aesthetic of the ribbon geom.
I experimented with other ways of filling the ribbon, together with a steady variable (so eg darker blue for extra optimistic, darker pink for extra unfavorable) however they weren’t as visually efficient as the only red-blue distinction.
Right here’s the code to attract that plot:
pict_indicators |>
ggplot(aes(x = Yr, y = nmr)) +
facet_wrap(~nation, ncol = 7, scales = "mounted") +
geom_line(color = "grey50", linetype = 1, linewidth = 0.4) +
geom_ribbon(aes(ymin = 0, ymax = nmr, fill = migration_direction), alpha = 0.5) +
scale_y_continuous(label = percent_format(scale = 1)) +
scale_fill_gradient2(low = "pink", excessive = "blue") +
labs(title = "Web migration affect on Pacific island nations and territories",
subtitle = "Nations proven in sequence of least proportionately impacted to most",
x = "",
y = "Web migration as a proportion of inhabitants in residence") +
theme(legend.place = "none",
axis.textual content.x = element_text(dimension = 7, color = "grey50"),
panel.grid.minor = element_blank())
The second plot makes use of the identical information in a special presentation. As a result of it’s a bit extra cluttered, I picked simply six nations or territories to indicate:
The stable blue line is the full inhabitants development. The dashed inexperienced line is the ‘pure’ development ie births minus deaths. The dotted pink line is the web migration we have been simply taking a look at. You may consider the pink line as dragging down (or very sometimes, up) the inexperienced line to get you the stable blue line because the sum of the 2. Or you may think about, if there have been no pink line in any respect, the inexperienced line can be the full inhabitants development. This was a pleasant speaking level and I feel enhances the primary chart properly.
It’s a reasonably dramatic story if you consider the inexperienced dashed line being dragged all the way down to the blue line by migration! Take a look at Niue, Marshall Islands or Samoa (migration vastly vital) in comparison with Kiribati or Papua New Guinea (not a lot).
The vital design selection is to make use of a stable line for the general whole, and dashed and dotted strains for the 2 elements of it. I feel this makes it simpler to comply with, ie making the full the eye-catchingly stable line. A couple of secondary issues to notice: another excuse to make use of dashes and dots along with the pink and inexperienced distinction is due to the comparatively excessive frequency of red-green colourblind folks; and I additionally fastidiously make sure that the legend reveals the pure enhance, whole inhabitants, internet migration in the identical vertical sequence as they seem within the plots.
Right here’s the code for this straightforward chart:
chosen <- c("Niue", "Marshall Islands", "Samoa", "Kiribati", "Northern Mariana Islands", "Papua New Guinea")
pict_indicators |>
filter(nation %in% chosen) |>
choose(nation, Yr, `Web migration acquire/loss` = nnm, `Pure enhance` = nc, `Whole enhance` = laptop) |>
collect(variable, worth, -Yr, -nation) |>
mutate(variable = fct_relevel(variable, "Web migration acquire/loss", after = Inf)) |>
ggplot(aes(x = Yr, y = worth, color = variable, linetype = variable)) +
facet_wrap(~nation, ncol = 3, scales = "free_y") +
geom_hline(yintercept = 0, color = "grey50") +
geom_line() +
scale_colour_manual(values = c("darkgreen", "blue", "pink")) +
scale_linetype_manual(values = c(2,1,3)) +
labs(y = "Annual change in inhabitants (1000's)",
x = "",
color = "", linetype = "")
That’s all for now! Developing in subsequent posts—diaspora, the world’s largest Pacific cities, and remittances.
