범주형 변수 시각화

R로 하는 설문 데이터 분석

Kelly McConville

Assistant Professor of Statistics

NHANES: 인종 시각화

library(dplyr)
tab_unw <- NHANESraw %>% group_by(Race1) %>%
   summarize(Freq = n()) %>% mutate(Prop = Freq / sum(Freq)) %>%
   arrange(desc(Prop))

tab_unw
# A tibble: 5 x 3
     Race1  Freq      Prop
    <fctr> <int>     <dbl>
 1    White  7393 0.3643128
 2    Black  4640 0.2286503
 3  Mexican  3739 0.1842507
 4    Other  2312 0.1139309
 5 Hispanic  2209 0.1088553

NHANES 문서

R로 하는 설문 데이터 분석

NHANES: 인종 시각화

library(ggplot2)
ggplot(data = tab_unw, mapping = aes(x = Race1, y = Prop)) + 
  geom_col() + 
  coord_flip() + 
  scale_x_discrete(limits = tab_unw$Race1) # Labels layer omitted

인종 분포의 비가중 막대그래프

R로 하는 설문 데이터 분석

NHANES: 인종 시각화

library(ggplot2)
ggplot(data = tab_unw, mapping = aes(x = Race1, y = Prop)) + 
  geom_bar(stat = "identity") + 
  coord_flip() + 
  scale_x_discrete(limits = tab_unw$Race1) # Labels layer omitted

인종 분포의 비가중 막대그래프

R로 하는 설문 데이터 분석

NHANES: 인종 시각화

library(ggplot2)
ggplot(data = tab_unw, mapping = aes(x = Race1, y = Prop)) + 
  geom_col() + 
  coord_flip() + 
  scale_x_discrete(limits = tab_unw$Race1) # Labels layer omitted

인종 분포의 비가중 막대그래프

R로 하는 설문 데이터 분석

NHANES: 인종 시각화

tab_w <- svytable(~Race1, design = NHANES_design) %>%
   as.data.frame() %>%
   mutate(Prop = Freq / sum(Freq)) %>%
   arrange(desc(Prop))

tab_w
     Race1      Freq       Prop
1    White 193966274 0.63748664
2    Black  37241616 0.12239773
3  Mexican  30719158 0.10096112
4    Other  23389002 0.07686994
5 Hispanic  18951150 0.06228456
R로 하는 설문 데이터 분석

NHANES: 인종 시각화

ggplot(data = tab_w, mapping = aes(x = Race1, y = Prop)) + 
  geom_col() + 
  coord_flip() + 
  scale_x_discrete(limits = tab_w$Race1) # Labels layer omitted

인종 분포의 가중 막대그래프

R로 하는 설문 데이터 분석

연습해 봅시다!

R로 하는 설문 데이터 분석

Preparing Video For Download...