library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
library(gganimate)
## Warning: package 'gganimate' was built under R version 4.3.3
library(gifski)
## Warning: package 'gifski' was built under R version 4.3.3
library(gapminder)
## Warning: package 'gapminder' was built under R version 4.3.3
### Animation Life Expectancy vs GDP Per Capital by Country ###
animated_plot <- ggplot(gapminder, aes(x = gdpPercap, y = lifeExp, size = pop, color = continent, frame = year, country = country)) +
geom_point(alpha = 0.7) +
scale_x_log10() + # Use logarithmic scale for GDP per capita
labs(
title = "Life Expectancy vs GDP Per Capital by Country",
x = "GDP Per Capita (log scale)",
y = "Life Expectancy",
color = "Continent"
) +
theme_minimal() +
transition_time(year) +
labs(title = "Year: {frame_time}")
animate(animated_plot, renderer = gifski_renderer("life_expectancy_vs_gdp.gif"))

### Box plot ###
ggplot(gapminder, aes(x = factor(cut(gdpPercap, breaks = 5)), y = lifeExp)) +
geom_boxplot() +
labs(
title = "Life Expectancy vs GDP Per Capita by Country",
x = "GDP Per Capital",
y = "Life Expectancy"
) +
theme_minimal()
