How long will you live?
Hi, my name is Linus, and I’m a developer in the app team at Datawrapper. Today, we’re looking at how long people can expect to live depending on where in the world they live and their gender.
If I had to answer the question, honestly and directly: it’s impossible to say. There is no way to pinpoint exactly how long a person will live, since there are so many contributing factors and different ways that we can die, from declining health to sudden accidents. However, we can get a rough idea when we look at wider population statistics. Life expectancy is a measure that stands for “the average number of years a newborn is expected to live if current death rates stay the same throughout their life,” according to World Population Review.
In 2024, the global average life expectancy was 73.8 years. However, lots of factors affect our chances. The most notable and best documented ones are where you live and whether you’re a man or a woman. To look at the impact of these factors, I decided to use an unusual but fascinating chart type: a beeswarm plot.
We see that there’s a stark difference between the lowest and highest end: life expectancy ranges from 53.4 years for men in Chad to 88.6 years for women in Monaco. That’s a difference of around 35 years!
The geographical difference
People in wealthier, more developed countries tend to live longer. There is a clear correlation between GDP per capita and life expectancy, famously visualized by Gapminder. While the differences between countries are affected by many factors, the main ones are differences in public health, medical care, and diet, typically more widely accessible in developed economies.
For example, in my country, Finland, we have a higher than average life expectancy of 84.8 years for women and 79.4 years for men. This matches the expectations since we have a high GDP per capita and a well-built public healthcare system. Some geographical differences also come from diets typical for certain regions, like the famous Mediterranean diet, known for leading to a longer life.
The life expectancy gender gap
On average, women live longer than men in all countries. This gap also exists in other mammals. According to a study, females live about 13% longer in 72% of species. But it can’t all be biological, since, as we see in the chart, there are big variations in the gender gap between countries. In Russia, women live almost 12 years longer than men, while in Norway, they only live 3 years longer.
There are a few reasons: men engage more in risky behaviors such as smoking and drinking, they are more likely to die from suicide or homicide, and finally, men are less likely to protect themselves from the sun and less likely to seek early medical care. How relevant these facts are varies between countries (in some countries, men drink a lot more than women, while in some countries it’s closer to equal), which explains the variance of the gap.
What is a beeswarm plot?
The chart above is a beeswarm plot, fittingly named for the shape of the cluster of data points. It is useful for visualizing one-dimensional data, where many values are close to each other and would overlap if placed directly along one axis. The defining feature of the beeswarm is that it gives data points an artificial y-value and more room to breathe, which prevents overlapping.
How to create a beeswarm plot in Datawrapper
If you have a dataset with one-dimensional data, like the source dataset for this chart, you can use an algorithm to create the offset y-axis values.
For this Weekly Chart, I used the beeswarm package in R. (There are many implementations in various programming languages.)
Since I do not have much experience with R, I used an LLM chatbot to create a script which reads the original dataset, computes the offset y-axis values using the beeswarm package, and saves it as a new CSV.
R script
A few tips for co-creating the script with an LLM chatbot
I recommend pasting your CSV into the chat and describing what you want the final data to look like. In this case, the input data had one row per country and one column per gender. I wanted the final version to have two rows per country, one for male data and one for female, and to keep the original columns for tooltips.
Also, ask for all the adjustable parameters to be defined as constants with clear, descriptive names at the beginning of the script, and for comments that describe the changes made so you can easily tweak the result if needed (see the “adjustable parameters” block at the top of the script below).
The script I used:
```jsx
library(beeswarm)
# ============================================================
# ADJUSTABLE PARAMETERS
# ============================================================
# --- Input / output files ---
INPUT_FILE <- "life-expectancy-by-country-2026-with-continent.csv"
OUTPUT_FILE <- "life-expectancy-by-country-2026_swarm.csv"
# --- Source columns for each gender series ---
FEMALE_COL <- "LifeExpectancyFemalesUN_2024"
MALE_COL <- "LifeExpectancyMalesUN_2024"
# --- Swarm shape controls (change how the point cloud looks) ---
SWARM_SPACING <- 1.5 # gap between points; higher = wider, looser cloud
SWARM_HALF_WIDTH <- 2 # half-height of each cloud; total spread = 2 x this
# --- Cloud separation ---
CLOUD_OFFSET <- 2.3 # female cloud sits at -offset, male at +offset
# Note: clouds overlap if CLOUD_OFFSET < SWARM_HALF_WIDTH; increase to separate.
# ============================================================
# SCRIPT
# ============================================================
df <- read.csv(INPUT_FILE, stringsAsFactors = FALSE, check.names = FALSE)
# Keep both-gender values on every row for downstream use
df$life_expectancy_female <- df[[FEMALE_COL]]
df$life_expectancy_male <- df[[MALE_COL]]
# Compute mirrored swarm offsets for one value column,
# rescaled so the cloud is exactly +/- half_width tall.
swarm_y <- function(values, half_width = SWARM_HALF_WIDTH, spacing = SWARM_SPACING) {
pdf(file = NULL) # suppress plot output
bs <- beeswarm(values, method = "swarm", spacing = spacing)
dev.off()
raw <- bs$x - 1
raw / max(abs(raw)) * half_width
}
# Build one swarm table per gender, sorted by value, with a vertical offset.
make_swarm <- function(data, value_col, gender_label, offset) {
d <- data[order(data[[value_col]]), ]
data.frame(
continent = d$Continent,
country = d$country,
life_expectancy = d[[value_col]],
gender = gender_label,
y = swarm_y(d[[value_col]]) + offset,
life_expectancy_female = d$life_expectancy_female,
life_expectancy_male = d$life_expectancy_male,
stringsAsFactors = FALSE
)
}
females <- make_swarm(df, FEMALE_COL, "Female", -CLOUD_OFFSET)
males <- make_swarm(df, MALE_COL, "Male", CLOUD_OFFSET)
swarm <- rbind(females, males)
write.csv(swarm, OUTPUT_FILE, row.names = FALSE)
```Once the data is ready, you can go to Datawrapper, create a new chart, upload the beeswarm dataset, and choose the scatterplot chart type. You can then fine-tune the appearance, like the size of dots and chart dimensions, in the editor. (If needed, you can go back to your script, adjust the parameters, run it again, and update the data.)
Finally, do not forget to check the mobile version for any unwanted overlap. And you're done!
That's all for this week! I hope you enjoyed it, and don’t be afraid to try out a beeswarm plot if you find yourself with a fitting dataset. Come back next week for another Weekly Chart by one of my colleagues.



