I used chatgpt to generate ” midpoint = 3,” because I was looking for a way to properly center the color scale in the heatmap so that it would show which fertility rates are above or below an important average.
Essay
For this visualization, I used the gapminder dataset from the dslabs package to explore changes in fertility rates over time across continents. Specifically, I focused on five selected years 1970, 1980, 1990, 2000, and 2010, to highlight trends in fertility transitions without overwhelming the viewer with too much data.Unlike the example in the tutorial, which used a scatterplot with fertility on the x-axis, life expectancy on the y-axis with point size representing population, I created a heatmap to show how median fertility rates have changed over time by continent. Instead of comparing individual countries to show a clearer view of broad regional patterns over time on a global scale.
First, I filtered the dataset to include only those years and grouped the data by continent and year. Then, I calculated the median fertility rate for each continent in each selected year. Next, I created a heatmap using ggplot2 to display how median fertility rates changed over time across continents. The visualization maps the year to the x-axis, continent to the y-axis, and median fertility rate to the fill color of each tile. Each combination of year and continent is represented as a colored rectangle, creating the heatmap effect.
To visually differentiate fertility levels,I used scale_fill_gradient2() instead of a regular gradient to clearly highlight whether fertility rates are above, below, or near the midpoint, making differences across continesnts and years more visually distinct. Labels for the title and axes are added with labs(), providing context for the viewer. Finally, I used theme_classic() instead of theme_minimal() this time because I thought it looked way better and was also looking to try a new theme in this project.