library(ggplot2)
library(gapminder)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
# Create box plots for life expectancy by continent
ggplot(gapminder, aes(x = continent, y = lifeExp, fill = continent)) +
  geom_boxplot() + # Create boxplot, fill colors by continent
  labs(title = "Life Expectancy by Continent",
       subtitle = "this is my subtitle!",
       x = "Continent", y = "Life Expectancy") + # Add labels and title
  theme_minimal() # Use a minimal theme for a clean look

gapminder %>% group_by(continent) %>% summarize(mean_lifeExp = mean(lifeExp, na.rm = TRUE))
## # A tibble: 5 × 2
##   continent mean_lifeExp
##   <fct>            <dbl>
## 1 Africa            48.9
## 2 Americas          64.7
## 3 Asia              60.1
## 4 Europe            71.9
## 5 Oceania           74.3

In the chart and visual representation, life expectancy varies significantly across continents according to data from Gapminder. Europe exhibits the highest average life expectancy at 71.90 years, followed by Oceania at 74.33 years, and the Americas at 64.66 years. Asia has an average life expectancy of 60.06 years, while Africa has the lowest at 48.87 years. These statistics are visually depicted through box plots, which illustrate the range and distribution of life expectancies within each continent. The top three continents also show narrower interquartile ranges alongside their higher median life expectancies. A narrow interquartile range on a box plot indicates that the middle 50% of the data points (between the 25th and 75th percentiles) are closely clustered together, suggesting less variability in life expectancy within those regions. Europe, with the narrowest range, reflects more consistent life expectancy outcomes across its populations, pointing to generally superior health outcomes and healthcare access compared to Asia and particularly Africa, where life expectancy remains notably lower and more variable.

print('I did it!')
## [1] "I did it!"