#(1) Do one visualization
library(gapminder)
library(tidyverse)
data(gapminder)
head(gapminder)
## # A tibble: 6 x 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 = lifeExp)) +
geom_histogram(binwidth = 4, fill = "blue", color = "black", alpha = 0.7) + # Change bindwith and alpha values to see what happens
labs(title = "Histogram of Life Expectancy",
x = "Life Expectancy", y = "Count") + # Add labels and title
theme_minimal() # Use a minimal theme for a clean look
Based on the histogram for life Expectancy, we can see that it does not follow normal distribution and negatively skewed.
#(2) Show and interpret one descriptive statistic
# Calculate summary statistics by continent
gapminder %>% group_by(continent) %>% summarize(mean_lifeExp = mean(lifeExp, na.rm = TRUE),
median_lifeExp = median(lifeExp, na.rm = TRUE),
sd_lifeExp = sd(lifeExp, na.rm = TRUE))
## # A tibble: 5 x 4
## continent mean_lifeExp median_lifeExp sd_lifeExp
## <fct> <dbl> <dbl> <dbl>
## 1 Africa 48.9 47.8 9.15
## 2 Americas 64.7 67.0 9.35
## 3 Asia 60.1 61.8 11.9
## 4 Europe 71.9 72.2 5.43
## 5 Oceania 74.3 73.7 3.80
Based on the results, we can see that the mean life expectancy for Oceania is 74.326 years, for Europe is 71.904 years, for Asia is 60.065 years, for Americas is 64.659 years, for Africa is 48.865 years.
#(3) Print the phrase: I did it!
print('I did it!')
## [1] "I did it!"