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.

Load Dataset

# Load Dataset

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

# Clean Column Names

data <- janitor::clean_names(data)

# View Columns

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

Total Students

nrow(data)
## [1] 1200

Average Age

mean(data[[age_col]], na.rm = TRUE)
## [1] 15.92833

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"
  )

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

  • Limited visualization variety
  • More filters can be added
  • Dashboard can be more interactive

Future Improvements

  • Add machine learning models
  • Add real-time filtering
  • Include advanced charts and heatmaps

Conclusion

This project demonstrates how R and visualization tools can be used effectively for analyzing teen mental health data.

The dashboard provides meaningful insights into stress, anxiety, sleep habits, and social media usage among teenagers.