Cities with Nice Weather

Jesse Onland

2022-05-12

Introduction

I live near Toronto. It’s springtime, and currently about 30 °C. In my opinion, Toronto is too hot in the summer and too cold in the winter. I’d like to know which cities have the least deviation from a tolerable average temperature.

Tools

This page was generated from an R markdown file. I’m using the tidyverse for data wrangling, ggplot2 and ggExtra to plot, and tufte and ggthemes for theming.1 For aesthetic reasons, the assignment and pipe operators are rendered as “⭠” and “▷” in this document respectively. If you would like to run the code you see here, be sure to change them back to “<-” and “|>”.

Data

First, I created a CSV file comprising all the information in the Wikpedia article List of cities by average temperature.

city_temps ⭠
  read_csv("temps.csv", show_col_types = FALSE)

head(city_temps)
Country City Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Year
Algeria Algiers 11.2 11.9 12.8 14.7 17.7 21.3 24.6 25.2 23.2 19.4 15.2 12.1 17.4
Algeria Tamanrasset 12.8 15.0 18.1 22.2 26.1 28.9 28.7 28.2 26.5 22.4 17.3 13.9 21.7
Algeria Reggane 16.0 18.2 23.1 27.9 32.2 36.4 39.8 38.4 35.5 29.2 22.0 17.8 28.3
Angola Luanda 26.7 28.5 28.6 28.2 27.0 23.9 22.1 22.1 23.5 25.2 26.7 26.9 25.8
Benin Cotonou 27.3 28.5 28.9 28.6 27.8 26.5 25.8 25.6 26.0 26.7 27.6 27.3 27.2
Benin Parakou 26.5 28.7 29.6 29.0 27.5 26.1 25.1 24.7 25.0 26.1 26.6 26.1 26.8

Each row corresponds to a distinct city. There are two text columns containing each city’s name and country, twelve numeric columns indicating the “averages of the daily highs and lows”1 This is a bit ambiguous, but no matter. The article also points out that “the actual daytime temperature in a given month will be 3 to 10 °C higher than the temperature listed here, depending on how large the difference between daily highs and lows is.” for each month, and one additional numeric column containing the same figure for the entire year. The units are degrees Celsius. 455 cities are included in the data.

We’ll define the “deviation” mentioned above as the difference between the value recorded for the coldest and hottest months, and the “average” as the value recorded for the whole year overall.

We’ll ignore any other weather characteristics like humidity, rain, wind, diurnal temperature difference, etc.2 This may or many not be reasonable depending on your personal preferences about weather.

city_temps ⭠
  city_temps ▷
  rename_with(tolower) ▷
  rowwise() ▷
  transmute(
    city,
    avg = year,
    range = max(c_across(jan:dec)) - min(c_across(jan:dec))
  )

head(city_temps)
city avg range
Algiers 17.4 14.0
Tamanrasset 21.7 16.1
Reggane 28.3 23.8
Luanda 25.8 6.5
Cotonou 27.2 3.3
Parakou 26.8 4.9

Summary Statistics

Now we can investigate the distribution of each of our two variables.

Here are the default summaries:

city_temps ▷ 
  select(avg, range) ▷
  summarize()
N Mean SD Min Q1 Median Q3 Max
avg 455 18.00 8.12 -14.4 12.45 18.6 25.65 30.5
range 455 13.75 9.53 0.7 5.65 12.1 21.00 58.1

Which cities correspond to the extremes for each variable?

city_temps ▷
  filter(
    avg   %in% (city_temps ▷ pull(avg)   ▷ range()) || 
    range %in% (city_temps ▷ pull(range) ▷ range())
  ) ▷
  arrange(avg)
city avg range
Gjoa Haven -14.4 42.0
Yakutsk -8.8 58.1
Honiara 26.5 0.7
Assab 30.5 8.7

Let’s see the values for Toronto as a baseline, and save them for later:

city_temps ▷
  filter(city == "Toronto")
city avg range
Toronto 9.4 26
toronto_avg ⭠
  city_temps ▷
  filter(city == "Toronto") ▷
  pull(avg)

toronto_range ⭠
  city_temps ▷
  filter(city == "Toronto") ▷
  pull(range)

By global standards, Toronto is cool on average, but in keeping with my subjective perception, the deviation from that average over the year is quite large.

Plots

Let’s look at a scatter plot with marginal histograms:

plot ⭠
  city_temps ▷
  ggplot(aes(x = avg, y = range)) +
  geom_point(alpha = 0.33) +
  geom_vline(
    xintercept = toronto_avg,
    linetype = "dashed",
    alpha = 0.33
  ) +
  geom_hline(
    yintercept = toronto_range,
    linetype = "dashed",
    alpha = 0.33
  ) +
  labs(
    title = "Average Temperature vs Range by City",
    x = "Average Temperature (°C)",
    y = "Difference Between Hottest and Coldest Months (°C)"
  ) +
  theme_tufte()

plot ⭠
  plot ▷
  ggMarginal(type = "histogram", fill = "transparent", size = 10)

plot

Here Toronto is indicated by the dashed lines.

We can see there’s a negative association between a city’s average temperature and the range of temperatures experienced there. In particular, there’s a big cluster of very hot cities which have little difference between their hottest and coldest months.

Ten tropical cities fall into both the hottest decile and the least varying decile:

city_temps ▷ 
  filter(
    range < quantile(city_temps$range, 0.1),
    avg   > quantile(city_temps$avg,   0.9)
  ) ▷
  select(city)
city
Lodwar
Palembang
Pontianak
Kuala Lumpur
Malé
Lanka Colombo
Oranjestad
Willemstad
Panama City
Barranquilla

While these cities see very little temperature variation throughout the year, they are much too hot.

Zooming In

The area of this plot I’m most interested in is the vertical slice around Toronto. Let’s see the same plot, including only the cities within one degree of Toronto’s average temperature.3 I haven’t defined an ideal average temperature, but any city with a similar average and smaller range than Toronto is a clear improvement. We’ll exclude the marginal histograms but add labels to the cities.

city_temps ▷
  filter(abs(avg - toronto_avg)<=1) ▷
  ggplot(aes(x = avg, y = range, label = city)) +
  geom_point(alpha = 0.33) +
  geom_text(size = 4, nudge_x = 0.01, hjust = "left") +
  geom_vline(
    xintercept = toronto_avg,
    linetype = "dashed",
    alpha = 0.33
  ) +
  geom_hline(
    yintercept = toronto_range,
    linetype = "dashed",
    alpha = 0.33
  ) +
  labs(
    title = "Average Temperature vs Range by City (Detail 1)",
    x = "Average Temperature (°C)",
    y = "Difference Between Hottest and Coldest Months (°C)"
  ) + 
  theme_tufte()

So it seems that La Paz, Edinburgh, or Dublin might be good options.

But which cities are the best? These would be the ones with the smallest range for a given maximum average. Let’s find them.

Finding the Cities with the Nicest Weather

We want to know, for each maximum average temperature, the city that has the minimum range of temperatures. These are the cities that form the “bottom-left edge” of our first plot.

Nine cities fit this criterion:

city_temps ▷
  arrange(avg) ▷
  cbind(city_temps ▷ arrange(avg) ▷ pull(range) ▷ cummin()) ▷
  rename(running_min = 4) ▷
  filter(range == running_min) ▷
  select(city)
city
Gjoa Haven
Dikson
Nuuk
Reykjavík
Stanley
La Paz
Cusco
Bogotá
Honiara

Of these, the first two have temperatures which are more variable than Toronto, so we can remove them from consideration.

Let’s plot the final seven candidates:

city_temps ▷
  arrange(avg) ▷
  cbind(city_temps ▷ arrange(avg) ▷ pull(range) ▷ cummin()) ▷
  rename(running_min = 4) ▷
  filter(range == running_min) ▷
  select(-running_min) ▷
  filter(range <= toronto_range) ▷
  ggplot(aes(x = avg, y = range, label = city)) +
  geom_point(alpha = 0.33) +
  geom_text(size = 4, nudge_x = 0.5, hjust = "left") +
  geom_vline(
    xintercept = toronto_avg,
    linetype = "dashed",
    alpha = 0.33
  ) +
  scale_x_continuous(expand = expansion(mult = 0.15)) +
    labs(
    title = "Average Temperature vs Range by City (Detail 2)",
    x = "Average Temperature (°C)",
    y = "Difference Between Hottest and Coldest Months (°C)"
  ) + 
  theme_tufte()

Again we see that La Paz has a similar overall average temperature to Toronto, but much less annual variability. Cusco and Bogotá are warmer but even less variable.

Reykjavík and Stanley are colder than Toronto, and while they represent a smaller decrease in variability compared to La Paz, Cusco, and Bogotá, they have the benefit (for me) of being 98%+ English-speaking.

Nuuk and Honiara are right out.

Next Steps

It would be interesting to use detailed time series for each city and a utility function on temperatures (perhaps including wind chill and humidex) to determine which cities are truly mean-variance optimal.

Of course, one should probably not choose a place to live based solely on the weather.