highchart() %>%
hc_add_series(
data = gapminder %>% filter(year >= 1990),
type = "heatmap",
hcaes(x = fertility, y = life_expectancy, group = region),
marker = list(radius = 5, symbol = "circle")
) %>%
hc_title(text = "Life Expectancy vs. Fertility Rate by Region") %>%
hc_xAxis(title = list(text = "Fertility Rate (Children per Woman)")) %>%
hc_yAxis(title = list(text = "Life Expectancy (Years)")) %>%
hc_legend(enabled = TRUE)To analyze trends in life expectancy by region over recent years, I used the ‘gapminder’ dataset from the ‘dslabs’ package. This dataset offers a comprehensive look at global development indicators, including life expectancy, fertility rates, and GDP across countries and regions. For clarity and focus on more recent trends, I filtered the dataset to include only data from 1990 onward.
To create the visualization, I used ‘ggplot2’ and ‘highcharter’. First, with ‘ggplot2’, I created a heatmap where ‘year’ is plotted on the x-axis, ‘region’ on the y-axis, and ‘life_expectancy’ represented by color intensity. The ‘geom_tile()’ function was used to make this heatmap, and I customized the color scheme with ‘scale_fill_viridis_c()’ for clear contrast. For a clean and engaging presentation, I used the minimal theme and adjusted the title and axis labels for readability.
Then, with ‘highcharter’, I added interactivity to allow users to hover over each point for detailed values. Here, life expectancy is plotted against fertility rates by region, adding an interactive layer that improves data exploration.