Copy the complete code below into a new .Rmd file.
---
title: "Teen Mental Health Dashboard Using R Shiny"
author: "Shweta Jawariya"
date: "2026-05-27"
output:
html_document:
toc: true
toc_float: true
theme: cosmo
---
# Introduction
Teen mental health has become an important topic due to increasing academic pressure, social media exposure, lifestyle changes, and emotional stress among students.
This project focuses on analyzing teen mental health patterns using interactive visualizations developed in R.
# Load Dataset
``` r
# Load Dataset
data <- read.csv("Teen_Mental_Health_Dataset.csv")
# Clean column names automatically
data <- janitor::clean_names(data)
# View column names
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
``` r
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
```
# Project Objectives
- Analyze teen mental health patterns
- Study stress and anxiety levels
- Understand impact of sleep and social media usage
- Create visualizations using R
- Build dashboard insights
# Total Students
``` r
nrow(data)
```
```
## [1] 1200
```
# Average Age
``` r
mean(data$age, na.rm = TRUE)
```
```
## [1] 15.92833
```
# Age Distribution
``` r
ggplot(data, aes(x = age)) +
geom_histogram (fill = "skyblue",
color = "black",
bins = 10) +
theme_minimal() +
labs(
title = "Age Distribution",
x = "Age",
y = "Count"
)
```
<img src="Teen-Mental-Health-Dashboard-Using-R-_files/figure-html/unnamed-chunk-5-1.png" alt="" width="672" />
# Gender Distribution
``` r
ggplot(data, aes(x = gender, fill = gender)) +
geom_bar() +
theme_minimal() +
labs(
title = "Gender Distribution",
x = "Gender",
y = "Count"
)
```
<img src="Teen-Mental-Health-Dashboard-Using-R-_files/figure-html/unnamed-chunk-6-1.png" alt="" width="672" />
# Stress Level Distribution
``` r
ggplot(data, aes(x = stress_level)) +
geom_histogram(fill = "red",
color = "black",
bins = 10) +
theme_minimal() +
labs(
title = "Stress Level Distribution",
x = "Stress Level",
y = "Count"
)
```
<img src="Teen-Mental-Health-Dashboard-Using-R-_files/figure-html/unnamed-chunk-7-1.png" alt="" width="672" />
# Anxiety Level Analysis
``` r
ggplot(data, aes(x = anxiety_level)) +
geom_histogram(fill = "orange",
color = "black",
bins = 10) +
theme_minimal() +
labs(
title = "Anxiety Level Analysis",
x = "Anxiety Level",
y = "Count"
)
```
<img src="Teen-Mental-Health-Dashboard-Using-R-_files/figure-html/unnamed-chunk-8-1.png" alt="" width="672" />
# Sleep Hours vs Anxiety Level
``` r
ggplot(data, aes(x = sleep_hours,
y = anxiety_level)) +
geom_point(color = "blue") +
theme_minimal() +
labs(
title = "Sleep Hours vs Anxiety Level",
x = "Sleep Hours",
y = "Anxiety Level"
)
```
<img src="Teen-Mental-Health-Dashboard-Using-R-_files/figure-html/unnamed-chunk-9-1.png" alt="" width="672" />
# Social Media Usage Distribution
``` r
social_col <- names(data)[grepl("social", names(data), ignore.case = TRUE)][1]
ggplot(data, aes(x = .data[[social_col]])) +
geom_histogram(
fill = "purple",
color = "black",
bins = 10
) +
theme_minimal()
```
<img src="Teen-Mental-Health-Dashboard-Using-R-_files/figure-html/unnamed-chunk-10-1.png" alt="" width="672" />
# Academic Performance by Gender
``` r
ggplot(data,
aes(x = gender,
y = academic_performance,
fill = gender)) +
geom_boxplot() +
theme_minimal() +
labs(
title = "Academic Performance by Gender",
x = "Gender",
y = "Academic Performance"
)
```
<img src="Teen-Mental-Health-Dashboard-Using-R-_files/figure-html/unnamed-chunk-11-1.png" alt="" width="672" />
# 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.
# References
- https://www.r-project.org/
- https://ggplot2.tidyverse.org/
- https://shiny.posit.co/