library(ggplot2)
library(readxl)
library(ggthemes)
library(gridExtra)
library(dplyr)
library(tidyr)
library(modeest)
# Import Data
setwd("C:/Users/HP-14/Downloads")
data <- read_excel("data-socialmedia-terhadap-mental-health.xlsx")
head(data)
## # A tibble: 6 × 22
## Timestamp `1. What is your age?` Gender `3. Relationship Status`
## <dttm> <dbl> <chr> <chr>
## 1 2022-04-18 19:18:47 21 Male In a relationship
## 2 2022-04-18 19:19:28 21 Female Single
## 3 2022-04-18 19:25:59 21 Female Single
## 4 2022-04-18 19:29:43 21 Female Single
## 5 2022-04-18 19:33:31 21 Female Single
## 6 2022-04-18 19:33:48 22 Female Single
## # ℹ 18 more variables: `4. Occupation Status` <chr>,
## # `5. What type of organizations are you affiliated with?` <chr>,
## # `6. Do you use social media?` <chr>,
## # `7. What social media platforms do you commonly use?` <chr>,
## # `8. What is the average time you spend on social media every day?` <chr>,
## # `9. How often do you find yourself using Social media without a specific purpose?` <dbl>,
## # `10. How often do you get distracted by Social media when you are busy doing something?` <dbl>, …
pie_chart <- ggplot(data, aes(x = "", fill = Gender)) +
geom_bar(width = 1) +
coord_polar("y", start = 0) +
theme_minimal() +
labs(title = "Distribusi Gender") +
theme(axis.text.x = element_blank())
# Tampilkan pie chart sendiri
print(pie_chart)
data_responses <- c(
"Facebook, Twitter, Instagram, YouTube, Discord, Reddit",
"Facebook, Twitter, Instagram, YouTube, Discord, Reddit",
"Facebook, Instagram, YouTube, Pinterest",
"Facebook, Instagram",
"Facebook, Instagram, YouTube",
"Facebook, Twitter, Instagram, YouTube, Discord, Pinterest, TikTok",
"Facebook, Instagram, YouTube, Snapchat, TikTok",
"Facebook, Instagram, YouTube",
"Facebook, Instagram, YouTube",
"Reddit, Pinterest",
"Facebook, Instagram, YouTube, Discord",
"Facebook, Instagram, YouTube, Snapchat, Discord, Reddit, Pinterest, TikTok",
"Facebook, Twitter, Instagram, YouTube, Snapchat, Discord, Reddit, Pinterest",
"Facebook, Twitter, Instagram, YouTube, Snapchat, Reddit, Pinterest",
"Facebook, YouTube, Pinterest",
"Facebook, Instagram, YouTube, Reddit",
"Facebook, YouTube, Discord",
"Facebook, Instagram, YouTube, Reddit",
"Facebook, YouTube, Discord, Reddit",
"Facebook, Twitter, Instagram, YouTube",
"Facebook, Instagram, YouTube, Discord, Reddit",
"Facebook, Twitter, Instagram, YouTube, Discord, Reddit, TikTok",
"Facebook, Instagram, YouTube, Pinterest",
"Facebook, Instagram, YouTube, Snapchat, Pinterest",
"Facebook, Twitter, YouTube, Discord",
"Facebook, YouTube",
"Facebook, Instagram, YouTube, Discord",
"Facebook, Twitter, Instagram, YouTube",
"Facebook, Instagram, YouTube, Snapchat, Discord, Pinterest, TikTok",
"Facebook, Instagram, YouTube, Snapchat, Discord"
)
# Mengubah data menjadi format yang bisa dihitung frekuensinya
data_frame <- data.frame(Platforms = unlist(strsplit(data_responses, ", "))) %>%
count(Platforms, sort = TRUE)
bar_chart <- ggplot(data_frame, aes(x = n, y = reorder(Platforms, n), fill = Platforms)) +
geom_bar(stat = "identity") +
coord_flip() +
theme_minimal() +
labs(title = " Platform Media Sosial Yang Digunakan", x = "Frekuensi", y = "Platform") +
theme(legend.position = "none")
# Tampilkan bar chart sendiri
print(bar_chart)
Terdapat 7 Platform Sosial Media yang sering digunakan oleh para responden, Seperti : Facebook, Instagram, YouTube, Snapchat, Discord, Reddit, Pinterest, TikTok.Dari hasil Bar Chart tersebut dapat dikatakan bahwa Facebook adalah platform sosial media yang sering digunakan
# 3. Dot Plot (Diagram Titik)
dot_plot <- ggplot(data, aes(x = `Gender`, y = `How often do you feel depressed or down?`)) +
geom_point(color = "violet", size = 2) +
theme_minimal() +
labs(title = "Dot Plot: Jenis Kelamin vs Tingkat Depresi", x = "Jenis Kelamin", y = "Tingkat Depresi")
print(dot_plot)
# 4. Histogram
histogram_data <- c(5,5,4,4,4,3,5,5,5,1,5,3,3,3,5,3,4,2,3,2,2,3,4,4,3,4,4,4,4,5)
df <- as.data.frame(table(histogram_data))
colnames(df) <- c("Individu", "Frekuensi")
df$Individu <- as.numeric(as.character(df$Individu))
hist_plot <- ggplot(df, aes(x=Individu, y=Frekuensi)) +
geom_bar(stat="identity", fill="cyan", color="black") +
geom_text(aes(label=Frekuensi), vjust=0.5, hjust=-0.2, size=5) +
labs(title="Histogram: Frekuensi Tingkat Depresi", x="Skor", y="Frekuensi") +
theme_minimal() +
coord_flip()
print(hist_plot)
# 5. Boxplot (Diagram Kotak)
boxplot_data <- ggplot(data) +
geom_boxplot(aes(y = `On a scale of 1 to 5, how often do you face issues regarding sleep?`, fill = "Masalah Tidur"), alpha = 0.6) +
theme_minimal() +
labs(title = "Box Plot: Masalah Tidur", fill = "Kondisi")
print(boxplot_data)
# 6. Density Plot (Diagram Kepadatan)
density_plot <- ggplot(data, aes(x = `14. Do you find it difficult to concentrate on things?`, fill = "Kesulitan Konsentrasi")) +
geom_density(alpha = 0.5) +
theme_minimal() +
labs(title = "Density Plot: Tingkat Kesulitan Berkonsentrasi", x = "Tingkat Kesulitan", y = "Kepadatan")
print(density_plot)
scatter_plot <- ggplot(data, aes(x = `8. What is the average time you spend on social media every day?`,
y = `How often do you feel depressed or down?`)) +
geom_point(color = "blue", alpha = 0.6) +
theme_minimal() +
labs(title = "Scatter Plot: Waktu di Sosial Media vs Tingkat Depresi",
x = "Jam per Hari di Sosial Media",
y = "Tingkat Depresi (1-5)")
print(scatter_plot)
line_chart_data <- data %>%
group_by(`8. What is the average time you spend on social media every day?`) %>%
summarise(mean_depression = mean(`How often do you feel depressed or down?`, na.rm = TRUE))
line_chart <- ggplot(line_chart_data, aes(x = `8. What is the average time you spend on social media every day?`,
y = mean_depression)) +
geom_line(color = "red", size = 1) +
geom_point(color = "red", size = 2) +
theme_minimal() +
labs(title = "Line Chart: Rata-rata Tingkat Depresi Berdasarkan Waktu di Sosial Media",
x = "Jam per Hari di Sosial Media",
y = "Rata-rata Tingkat Depresi")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
print(line_chart)
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
grid.arrange(
pie_chart, bar_chart, dot_plot, hist_plot,
boxplot_data, density_plot, scatter_plot, line_chart,
ncol = 2, nrow = 4
)
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
print(stats_depresi)
## $Mean
## [1] 3.7
##
## $Median
## [1] 4
##
## $Mode
## [1] 4
##
## $Q1
## 25%
## 3
##
## $Q3
## 75%
## 4.75
##
## $Range
## [1] 4
##
## $Variance
## [1] 1.182759
##
## $Standard_Deviation
## [1] 1.087547
print(stats_konsentrasi)
## $Mean
## [1] 3.333333
##
## $Median
## [1] 4
##
## $Mode
## [1] 4
##
## $Q1
## 25%
## 2.25
##
## $Q3
## 75%
## 4
##
## $Range
## [1] 4
##
## $Variance
## [1] 1.747126
##
## $Standard_Deviation
## [1] 1.321789
print(stats_tidur)
## $Mean
## [1] 2.8
##
## $Median
## [1] 2
##
## $Mode
## [1] 1
##
## $Q1
## 25%
## 1
##
## $Q3
## 75%
## 4.75
##
## $Range
## [1] 4
##
## $Variance
## [1] 2.648276
##
## $Standard_Deviation
## [1] 1.627352