koweps_h19_2024_beta1.sav 파일이다.raw_data <- read_sav("D:/Desktop/koweps_hpc19_2024_beta1.sav")# 원본 데이터
selected_data <- raw_data[, c("h19_g3", "h19_g4", "p1903_5")]# 대상 열 선택
cleaned_data <- selected_data[complete.cases(selected_data),]# NA 항목의 행 제거
colnames(cleaned_data) <- c("gender", "birth", "heal_sat")# 열 이름 변경
summary(cleaned_data$heal_sat)# 건강 만족도 개요
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 3.000 3.000 3.241 4.000 5.000
cleaned_data$gender <- ifelse(cleaned_data$gender == 1, "남성", "여성")# 성별 할당
table(cleaned_data$gender)# 성별 분포
##
## <U+B0A8><U+C131> <U+C5EC><U+C131>
## 5472 7243
summary(cleaned_data$birth)# 출생연도 개요
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1922 1948 1961 1964 1979 2006
cleaned_data$age <- 2025 - cleaned_data$birth# 나이
cleaned_data <- cleaned_data %>%
mutate(ageg = ifelse(age < 30, "청년층",
ifelse(age <= 59, "중년층", "노년층")))# 연령 파생 변수
cleaned_data <- cleaned_data %>%
mutate(satg = ifelse(heal_sat == c("1", "2"), "청년층",
ifelse(heal_sat == "3", "중년층", "노년층")))# 건강 만족도 파생 변수
## Warning: There was 1 warning in `mutate()`.
## i In argument: `satg = ifelse(...)`.
## Caused by warning in `heal_sat == c("1", "2")`:
## ! 长的对象长度不是短的对象长度的整倍数
gender_sat <- cleaned_data %>%
group_by(gender) %>%
summarise(mean_sat_gender = round(mean(heal_sat), 2)) %>%
arrange(desc(mean_sat_gender))
gender_sat
## # A tibble: 2 x 2
## gender mean_sat_gender
## <chr> <dbl>
## 1 <U+B0A8><U+C131> 3.36
## 2 <U+C5EC><U+C131> 3.15
age_sat <- cleaned_data %>%
group_by(age) %>%
summarise(mean_sat_age = mean(heal_sat))
age_sat
## # A tibble: 85 x 2
## age mean_sat_age
## <dbl> <dbl>
## 1 19 4.33
## 2 20 4
## 3 21 3.98
## 4 22 3.98
## 5 23 3.96
## 6 24 3.84
## 7 25 3.92
## 8 26 3.90
## 9 27 3.99
## 10 28 3.87
## # i 75 more rows
ageg_sat <- cleaned_data %>%
group_by(ageg) %>%
summarise(mean_sat_ageg = round(mean(heal_sat), 2))
ageg_sat
## # A tibble: 3 x 2
## ageg mean_sat_ageg
## <chr> <dbl>
## 1 <U+B178><U+B144><U+CE35> 2.9
## 2 <U+C911><U+B144><U+CE35> 3.63
## 3 <U+CCAD><U+B144><U+CE35> 3.91
sat_pct <- cleaned_data %>%
group_by(satg) %>%
summarise(n = n()) %>%
mutate(total = sum(n)) %>%
mutate(pct_sat = round(n/total*100, 2))
sat_pct
## # A tibble: 3 x 4
## satg n total pct_sat
## <chr> <int> <int> <dbl>
## 1 <U+B178><U+B144><U+CE35> 7485 12715 58.9
## 2 <U+C911><U+B144><U+CE35> 3752 12715 29.5
## 3 <U+CCAD><U+B144><U+CE35> 1478 12715 11.6
ggplot(data = gender_sat, aes(x = reorder(gender, -mean_sat_gender), y = mean_sat_gender)) +
geom_col(stat = "identity", fill = c("#104680", "#6dadd1"), width = 0.4) +
geom_text(aes(label = mean_sat_gender), vjust = -1.5) +
scale_y_continuous(limits = c(0, 4)) +
ggtitle("성별별 건강 만족도") +
theme(plot.title = element_text(face = "bold", hjust = 0.5, size = 15, color = "darkblue")) +
labs(x = "성별", y = "건강 만족도")
## Warning in geom_col(stat = "identity", fill = c("#104680", "#6dadd1"), width =
## 0.4): Ignoring unknown parameters: `stat`
ggplot(data = age_sat, aes(x = age, y = mean_sat_age)) +
geom_line() +
stat_smooth(color = "#FC4E07", method = "auto") +
ggtitle("연령에 따른 건강 만족도") +
theme(plot.title = element_text(face = "bold", hjust = 0.5, size = 15, color = "darkblue")) +
labs(x = "연령", y = "건강 만족도")
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
ggplot(data = ageg_sat, aes(x = reorder(ageg, -mean_sat_ageg), y = mean_sat_ageg)) +
geom_col(stat = "identity", fill = c("#6dadd1", "#f6b293", "#b72230"), width = 0.4) +
geom_text(aes(label = mean_sat_ageg), vjust = -1.5) +
scale_y_continuous(limits = c(0, 5)) +
ggtitle("연령대별 건강 만족도") +
theme(plot.title = element_text(face = "bold", hjust = 0.5, size = 15, color = "darkblue")) +
labs(x = "연령대", y = "건강 만족도")
## Warning in geom_col(stat = "identity", fill = c("#6dadd1", "#f6b293",
## "#b72230"), : Ignoring unknown parameters: `stat`
ggplot(data = sat_pct, aes(x = " ", y = pct_sat, fill = satg)) +
geom_bar(stat = "identity") +
theme_void() +
coord_polar("y", start = 0) +
geom_text(aes(label = paste0(round(pct_sat, 1), "%")), position = position_stack(vjust = 0.5), color = "black", size = 5) +
ggtitle("전체 건강 만족도") +
theme(plot.title = element_text(face = "bold", hjust = 0.5, size = 15, color = "darkblue"))
#결론