5  Assignment 1

Published

November 23, 2023

5.1 Group Assignment For Global Dietary Database

In this analysis, we delve into the Global Dietary Database to scrutinize Vitamin B12 intake among Former Soviet Union countries. Employing the analytical prowess of ‘dplyr’ and ‘ggplot2’ in R, our aim is to uncover patterns and variations, offering a data-driven perspective on nutritional habits within this geopolitical region.

Global Dietary Database

Dataset


# Soviet Union data cleaned up and inserted average column by calculating the mean
soviet_union_abbreviations <- c("ARM", "AZE", "BLR", "EST", "GEO", "KAZ", "KGZ", "LVA", "LTU", "MDA", "RUS", "TJK", "TKM", "UKR", "UZB")

soviet_union_data <- data %>%
  filter(country %in% soviet_union_abbreviations)


# Full country names
country_names <- c(
  "Armenia", "Azerbaijan", "Belarus", "Estonia", "Georgia", "Kazakhstan", "Kyrgyzstan", "Latvia", "Lithuania", "Moldova",
  "Russia", "Tajikistan", "Turkmenistan", "Ukraine", "Uzbekistan"
)

# Replace country abbreviations with full names
soviet_union_data$country <- factor(soviet_union_data$country, levels = soviet_union_abbreviations, labels = country_names)

5.1.1 B12 Intakes Total Averages by Country

The following plot displays the total averages of B12 intakes for each country in the Former Soviet Union. The bars represent the mean B12 intake, providing an overview of the variations across the different countries.

# Group by Country
group_by_country_data <- soviet_union_data %>%
  group_by(country) %>%
  summarise(avg_b12 = mean(average, na.rm = TRUE))

# Plotting the data with geom_bar
ggplot(group_by_country_data, aes(x = country, y = avg_b12, fill = country)) +
  geom_bar(stat = "identity", position = position_dodge(width = 0.8), alpha = 0.7) +
  labs(title = "B12 Intakes Total Averages by Country",
       x = "Country",
       y = "B12 intakes Total Average") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_fill_viridis_d()  + 
  # Increase bar width
  theme(legend.position = "none") +
  geom_text(aes(label = round(avg_b12, 2)), vjust = -0.5, position = position_dodge(width = 0.8)) 


5.1.2 B12 Intakes Total Averages by Country and Gender

The following plot further breaks down the B12 intakes by gender within each country. The stacked bars show the mean B12 intake for both male and female individuals, providing insights into gender-specific patterns across the Former Soviet Union. ::: {.cell}

# Group by Country and Gender
group_by_country_gender_data <- soviet_union_data %>% filter(gender!='NA')%>%
  group_by(country, gender) %>%
  summarise(avg_b12 = mean(average, na.rm = TRUE), .groups = 'drop')

# Plotting the data with geom_bar (stacked)
ggplot(group_by_country_gender_data, aes(x = country, y = avg_b12, fill = factor(gender))) +
  geom_bar(stat = "identity", position = "stack", alpha = 0.7) +
  labs(title = "B12 Intakes Total Averages by Country and Gender",
       x = "Country",
       y = "B12 Intakes Total Average") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_fill_viridis_d(name = "Gender", labels = c("Male", "Female")) +
  # Increase bar width
  theme(legend.position = "top") +
  geom_text(aes(label = round(avg_b12, 2)), position = position_stack(vjust = 0.5))

:::


5.1.3 B12 Intakes Total Averages by Country and Year

This plot unveils the nuanced trends in mean B12 intake across years for Former Soviet Union countries. Stacked bars represent the average B12 intake, providing insights into variations over time within each country.

# Group by Year and Country
group_by_country_year_data <- soviet_union_data %>% filter(gender!='NA')%>%
  group_by(year, country) %>%
  summarise(avg_b12 = mean(average, na.rm = TRUE), .groups = 'drop')

# Plotting the data
ggplot(group_by_country_year_data, aes(x = year, y = avg_b12, color = country,alpha = 0.7)) +
  geom_line(linewidth = 1) +
  labs(title = "Average B12 intake by Year and Country",
       x = "Year",
       y = "Average B12 intake")