Project 1

Dataset Introduction

The dataset I will be using is from the United Nations accessed through the CORGIS datasets project. The dataset includes 21 quantitative variables, 2 qualitative variables, and 2,760 observations. The dataset has a bunch of metrics on the prevalence of aids from 1990 to 2020 across a ton of countries. The dataset can be accessed at: https://corgis-edu.github.io/corgis/csv/aids/ and is produced by UNAIDS.

Loading the Dataset + Setup

# Libraries
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(pheatmap)
library(viridis)
Loading required package: viridisLite
library(ggalluvial)
library(RColorBrewer)
library(treemap)

Above I load all the required libraries for this project.

# Load the dataset
df <- read_csv("aids.csv")
Rows: 2759 Columns: 23
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (1): Country
dbl (22): Year, Data.AIDS-Related Deaths.AIDS Orphans, Data.AIDS-Related Dea...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(df)
# A tibble: 6 × 23
  Country      Year Data.AIDS-Related Deaths.AIDS Orpha…¹ Data.AIDS-Related De…²
  <chr>       <dbl>                                 <dbl>                  <dbl>
1 Afghanistan  1990                                   100                    100
2 Algeria      1990                                   200                    100
3 Angola       1990                                  1300                    500
4 Argentina    1990                                   500                    200
5 Armenia      1990                                   100                    100
6 Azerbaijan   1990                                   100                    100
# ℹ abbreviated names: ¹​`Data.AIDS-Related Deaths.AIDS Orphans`,
#   ²​`Data.AIDS-Related Deaths.Adults`
# ℹ 19 more variables: `Data.AIDS-Related Deaths.All Ages` <dbl>,
#   `Data.AIDS-Related Deaths.Children` <dbl>,
#   `Data.AIDS-Related Deaths.Female Adults` <dbl>,
#   `Data.AIDS-Related Deaths.Male Adults` <dbl>,
#   `Data.HIV Prevalence.Adults` <dbl>, …

Above I load the dataset and view the first six rows and all the columns. The main columns I will focus on are the Data.New HIV Infections.All Ages, Data.HIV Prevalence.Adults, Country, and Year.

Visualizing the Data

Visualization 1: Heatmap

df_summarised <- df |> 
  group_by(Country) |> 
  summarise(
    count = n(),
    avg_prev = mean(`Data.HIV Prevalence.Adults`),
    avg_infections = mean(`Data.New HIV Infections.Adults`),
    avg_deaths = mean(`Data.AIDS-Related Deaths.Adults`),
    .groups = "drop") |> 
  arrange(avg_infections) |> 
  filter(avg_infections > 40000)
df_summarised
# A tibble: 10 × 5
   Country                     count avg_prev avg_infections avg_deaths
   <chr>                       <int>    <dbl>          <dbl>      <dbl>
 1 Thailand                       31     1.64         40732.     26529.
 2 Malawi                         31    11.6          55258.     30929.
 3 Uganda                         31     7.64         64065.     43387.
 4 Zambia                         31    12.3          70613.     30935.
 5 Kenya                          31     6.87         82871.     46858.
 6 Zimbabwe                       31    18.0          83226.     53000 
 7 Nigeria                        31     1.30         90516.     40816.
 8 United Republic of Tanzania    31     5.29         92613.     45290.
 9 Mozambique                     31     8.91         95032.     30445.
10 South Africa                   31    13.3         337452.     98158.
df_matrix <- data.matrix(df_summarised[, -1])
row.names(df_matrix) <- df_summarised$Country

Above I get the data prepared for being put into the Heatmap and Treemap.

pheatmap(df_matrix,
         cluster_rows = FALSE,
         cluster_cols = FALSE,
         scale = "column",
         display_numbers = round(df_matrix, 1),
         number_color = 'white',
         color = viridis(25),
         legend = FALSE,
         angle_col = 0,
         main = "Heatmap of Countries' HIV/AIDS Statistics")

The graph above is a heatmap of HIV/AIDS statistics based on country. From the graph you can see that Zimbabwe has the highest prevalence however the most infections and deaths are in South Africa due to it’s high population relative to the other nations. South Africa also has a higher prevalence however, being the second highest.

Visualization 2: Treemap

treemap(df_summarised,
        index = "Country",
        vSize = "count",
        vColor = "avg_prev",
        type = "value",
        palette = "-RdYlBu",
        title = "HIV Prevalence by Nation (10 Nations with Highest Infections)",
        title.legend = "Average Prevalence")

This is a treemap showing the prevalence of HIV in ten nations with the most average HIV cases per year since 1990. The treemap itself shows that HIV is most prevalent in Zimbabwe, South Africa, Zambia, and Malawi.