data (gapminder)
#See Structure
head(gapminder)
## # A tibble: 6 × 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Afghanistan Asia 1952 28.8 8425333 779.
## 2 Afghanistan Asia 1957 30.3 9240934 821.
## 3 Afghanistan Asia 1962 32.0 10267083 853.
## 4 Afghanistan Asia 1967 34.0 11537966 836.
## 5 Afghanistan Asia 1972 36.1 13079460 740.
## 6 Afghanistan Asia 1977 38.4 14880372 786.
ggplot(gapminder, aes(x = gdpPercap, y = lifeExp, size = pop, color = continent)) +
geom_point(alpha = 0.7) +
scale_x_log10() + # Use logarithmic scale for better visualization
labs(title = "Life Expectancy vs. GDP per Capita",
x = "GDP per Capita (log scale)",
y = "Life Expectancy",
size = "Population",
color = "Continent") +
theme_minimal()
#Step 2: Descriptive Statistic
# Calculate the mean life expectancy
mean_lifeExp <- gapminder %>%
summarize(mean_lifeExp = mean(lifeExp, na.rm = TRUE)) %>%
pull(mean_lifeExp)
# Display the mean life expectancy
mean_lifeExp
## [1] 59.47444
The mean life expectancy across all countries and years in the data is approximately 59.47 years. This value represents the average number of years a person is expected to live based on the combined data from all available countries and years in the data.
A mean life expectancy of 59.47 years suggests that, on average, people in the countries included in this data lived to be about 59 years old. This average takes into account all variations across different countries and years. It reflects the general health and living conditions during the periods covered by the data.
# Print the phrase
cat("I did it!\n")
## I did it!