Introduction

Teen mental health has become an important topic due to increasing academic pressure, social media exposure, emotional stress, and lifestyle changes among students.

This project analyzes teen mental health data using R visualizations and KPI metrics.

Load Dataset

data <- read.csv("Teen_Mental_Health_Dataset.csv")

data <- janitor::clean_names(data)

colnames(data)
##  [1] "age"                      "gender"                  
##  [3] "daily_social_media_hours" "platform_usage"          
##  [5] "sleep_hours"              "screen_time_before_sleep"
##  [7] "academic_performance"     "physical_activity"       
##  [9] "social_interaction_level" "stress_level"            
## [11] "anxiety_level"            "addiction_level"         
## [13] "depression_label"

Dataset Summary

summary(data)
##       age           gender          daily_social_media_hours platform_usage    
##  Min.   :13.00   Length:1200        Min.   :1.000            Length:1200       
##  1st Qu.:14.00   Class :character   1st Qu.:2.800            Class :character  
##  Median :16.00   Mode  :character   Median :4.500            Mode  :character  
##  Mean   :15.93                      Mean   :4.537                              
##  3rd Qu.:18.00                      3rd Qu.:6.300                              
##  Max.   :19.00                      Max.   :8.000                              
##   sleep_hours    screen_time_before_sleep academic_performance
##  Min.   :4.000   Min.   :0.50             Min.   :2.00        
##  1st Qu.:5.200   1st Qu.:1.10             1st Qu.:2.50        
##  Median :6.500   Median :1.80             Median :2.99        
##  Mean   :6.449   Mean   :1.74             Mean   :2.99        
##  3rd Qu.:7.600   3rd Qu.:2.40             3rd Qu.:3.48        
##  Max.   :9.000   Max.   :3.00             Max.   :4.00        
##  physical_activity social_interaction_level  stress_level    anxiety_level   
##  Min.   :0.000     Length:1200              Min.   : 1.000   Min.   : 1.000  
##  1st Qu.:0.500     Class :character         1st Qu.: 3.000   1st Qu.: 3.000  
##  Median :1.000     Mode  :character         Median : 5.000   Median : 6.000  
##  Mean   :1.014                              Mean   : 5.446   Mean   : 5.637  
##  3rd Qu.:1.500                              3rd Qu.: 8.000   3rd Qu.: 8.000  
##  Max.   :2.000                              Max.   :10.000   Max.   :10.000  
##  addiction_level  depression_label 
##  Min.   : 1.000   Min.   :0.00000  
##  1st Qu.: 3.000   1st Qu.:0.00000  
##  Median : 6.000   Median :0.00000  
##  Mean   : 5.565   Mean   :0.02583  
##  3rd Qu.: 8.000   3rd Qu.:0.00000  
##  Max.   :10.000   Max.   :1.00000

Detect Columns Automatically

age_col <- names(data)[grepl("age", names(data), ignore.case = TRUE)][1]

gender_col <- names(data)[grepl("gender", names(data), ignore.case = TRUE)][1]

stress_col <- names(data)[grepl("stress", names(data), ignore.case = TRUE)][1]

anxiety_col <- names(data)[grepl("anxiety", names(data), ignore.case = TRUE)][1]

sleep_col <- names(data)[grepl("sleep", names(data), ignore.case = TRUE)][1]

social_col <- names(data)[grepl("social", names(data), ignore.case = TRUE)][1]

academic_col <- names(data)[grepl("academic", names(data), ignore.case = TRUE)][1]

Convert Numeric Columns

data[[age_col]] <- as.numeric(data[[age_col]])

data[[stress_col]] <- as.numeric(data[[stress_col]])

data[[anxiety_col]] <- as.numeric(data[[anxiety_col]])

data[[sleep_col]] <- as.numeric(data[[sleep_col]])

data[[social_col]] <- as.numeric(data[[social_col]])

data[[academic_col]] <- as.numeric(data[[academic_col]])

Project Objectives

  • Analyze teen mental health patterns
  • Study stress and anxiety levels
  • Understand impact of sleep and social media usage
  • Create visualizations using R

KPI 1 - Total Students

total_students <- nrow(data)

total_students
## [1] 1200

KPI 2 - Average Stress Level

avg_stress <- round(mean(data[[stress_col]], na.rm = TRUE),2)

avg_stress
## [1] 5.45

KPI 3 - Average Anxiety Level

avg_anxiety <- round(mean(data[[anxiety_col]], na.rm = TRUE),2)

avg_anxiety
## [1] 5.64

KPI 4 - Average Sleep Hours

avg_sleep <- round(mean(data[[sleep_col]], na.rm = TRUE),2)

avg_sleep
## [1] 6.45

Age Distribution

ggplot(data,
       aes(x = .data[[age_col]])) +

  geom_histogram(
    fill = "skyblue",
    color = "black",
    bins = 10
  ) +

  theme_minimal() +

  labs(
    title = "Age Distribution",
    x = "Age",
    y = "Count"
  )

Gender Distribution

ggplot(data,
       aes(x = .data[[gender_col]],
           fill = .data[[gender_col]])) +

  geom_bar() +

  theme_minimal() +

  labs(
    title = "Gender Distribution",
    x = "Gender",
    y = "Count"
  )

Stress Level Distribution

ggplot(data,
       aes(x = .data[[stress_col]])) +

  geom_histogram(
    fill = "red",
    color = "black",
    bins = 10
  ) +

  theme_minimal() +

  labs(
    title = "Stress Level Distribution",
    x = "Stress Level",
    y = "Count"
  )

Anxiety Level Distribution

ggplot(data,
       aes(x = .data[[anxiety_col]])) +

  geom_histogram(
    fill = "orange",
    color = "black",
    bins = 10
  ) +

  theme_minimal() +

  labs(
    title = "Anxiety Level Distribution",
    x = "Anxiety Level",
    y = "Count"
  )

Sleep Hours vs Anxiety

ggplot(data,
       aes(x = .data[[sleep_col]],
           y = .data[[anxiety_col]])) +

  geom_point(color = "blue") +

  theme_minimal() +

  labs(
    title = "Sleep Hours vs Anxiety",
    x = "Sleep Hours",
    y = "Anxiety Level"
  )

Social Media Usage Distribution

ggplot(data,
       aes(x = .data[[social_col]])) +

  geom_histogram(
    fill = "purple",
    color = "black",
    bins = 10
  ) +

  theme_minimal() +

  labs(
    title = "Social Media Usage Distribution",
    x = "Social Media Usage",
    y = "Count"
  )

Academic Performance by Gender

ggplot(data,
       aes(x = .data[[gender_col]],
           y = .data[[academic_col]],
           fill = .data[[gender_col]])) +

  geom_boxplot() +

  theme_minimal() +

  labs(
    title = "Academic Performance by Gender",
    x = "Gender",
    y = "Academic Performance"
  )

Additional Visualization - Sleep Hours Distribution

ggplot(data,
       aes(x = .data[[sleep_col]])) +

  geom_histogram(
    fill = "green",
    color = "black",
    bins = 10
  ) +

  theme_minimal() +

  labs(
    title = "Sleep Hours Distribution",
    x = "Sleep Hours",
    y = "Count"
  )

Additional Visualization - Academic Performance Distribution

ggplot(data,
       aes(x = .data[[academic_col]])) +

  geom_histogram(
    fill = "darkblue",
    color = "black",
    bins = 10
  ) +

  theme_minimal() +

  labs(
    title = "Academic Performance Distribution",
    x = "Academic Performance",
    y = "Count"
  )

Dashboard Insights

  • Stress and anxiety levels vary among teenagers.
  • Sleep duration affects emotional health.
  • Social media usage may influence anxiety levels.
  • Gender comparison provides demographic insights.

Strengths

  • Interactive visualizations
  • Easy-to-understand analysis
  • KPI-based insights
  • Useful academic dashboard

Weaknesses

  • More advanced filters can be added
  • Dashboard can be more interactive

Future Improvements

  • Add machine learning models
  • Add heatmaps and trend analysis
  • Include advanced dashboard filters

Conclusion

This project demonstrates how R visualization tools can effectively analyze teen mental health patterns using charts and KPI metrics.