R_final_project.qmd

Author

Jayce

options(repos = c(CRAN = "https://cran.rstudio.com/"))

library(ggplot2)
library(readr)
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

#Introduction

This report presents a multi-domain data visualization analysis using three real-world datasets: pet adoption records, heart disease data, and global air quality statistics. The aim is to explore patterns within each dataset and generate insights using ggplot2 and quarto funtion in R. Each chart is followed by discussion and interpretation.

#Data Analysis

##Plot 1: Pet Age Distribution Analysis

Purpose: To understand the age distribution among different pet species.

# Load pet adoption center data
Data = read.csv("/Users/lianjayce/Downloads/pet_adoption_center.csv")

ggplot(Data) +
  aes(x = species, y = age_years, fill = species) +
  geom_boxplot(outlier.colour = "red") +
  labs(
    x = "Pet Species",
    y = "Age (years)",
    title = "Age Distribution by Pet Species"
  ) +
  theme_minimal()

Observations: This boxplot reveals the age distribution patterns across five pet species. Hamsters demonstrate the highest median age at approximately 8 years, with a relatively concentrated and low-variance distribution. Birds show the most compact age distribution, clustering primarily between 6-9 years with minimal outliers. In contrast, cats and dogs exhibit the greatest age variability, spanning from juveniles to seniors with numerous outlier points. Rabbits display a median age of around 6-7 years, with a distribution pattern falling between hamsters and cats/dogs.

Analysis: These distribution patterns reflect various underlying factors. The longer lifespan shown for hamsters in this chart may relate to specific care environments or data collection methods, as wild hamsters typically have shorter lifespans. The broad age range for cats and dogs likely reflects the diversity of the pet adoption market, where people are willing to adopt pets from puppyhood through senior years. The concentrated age distribution for birds may indicate that these pets are more commonly kept or recorded within specific age ranges.

#Plot 2: Heart Disease Analysis

Data2 = read.csv("/Users/lianjayce/Downloads/Heart_disease_statlog.csv")

ggplot(Data2) +
  aes(x = age, y = thalach, color = factor(target)) +
  geom_point(alpha = 0.7) +
  scale_color_manual(
    values = c("0" = "#1f77b4", "1" = "#d62728"),
    name = "Heart Disease Status",
    labels = c("No Disease", "Has Disease")
  ) +
  labs(
    title = "Heart Rate vs Age by Heart Disease Status",
    x = "Age",
    y = "Maximum Heart Rate"
  ) +
  theme_minimal() +
  theme(legend.position = "bottom")

Observations: This scatterplot displays the relationship between maximum heart rate and age across individuals aged 30-75, categorized by heart disease status. Blue dots represent individuals without heart disease, while red dots represent those with heart disease. Overall, there’s a declining trend in maximum heart rate with increasing age. In younger age groups (30-45 years), the no-disease group generally shows higher heart rates, with some individuals reaching 200 bpm. In older age groups (60+ years), the difference between groups appears to narrow, with overall heart rates declining to the 120-180 bpm range.

Analysis: This pattern aligns with physiological expectations, as maximum heart rate naturally declines with age. Notably, in middle-age groups, individuals with heart disease typically show lower maximum heart rates compared to healthy individuals, likely reflecting the impact of cardiac dysfunction on exercise capacity. However, the narrowing difference in older groups may indicate that age itself becomes the dominant factor in heart rate performance. The considerable data scatter also highlights significant individual variation, reminding us that multiple factors must be considered when assessing cardiac health.