사용데이터 : https://2stndard.tistory.com/161
기하 요소
일변수(One Variable) 데이터 시각화
연속형 수치 데이터
geom_freqpoly()
geom_freqpoly()
는 geom_histogram()
과
유사하게 연속형 일변수 수치 데이터의 빈도를 표현하는데 사용되는 기하
요소 함수이다. geom_histogram()
은 관측치의 빈도를 막대로
시각화하지만 geom_freqpoly()
는 데이터 값들을 연결한
다각형을 사용하여 데이터를 표현한다. geom_freqpoly()
도
geom_histogram()
과 같이 binning을 기본적으로 사용하기
때문에 통계 요소 ’bin’이 기본적으로 적용된다. 만약 다각형을 조금
부드럽게(smoothing) 하려면 통계 요소를 ’density’로 설정하는데 이 경우는
geom_density()
와 동일한 결과가 나온다.
geom_freqpoly(mapping = NULL, data = NULL, stat = "bin", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)\
- mapping : aes()를 사용하여 매핑할 미적 요소, 생략되면 ggplot()에 정의된 미적매핑 사용\
- data : 시각화를 위해 사용될 데이터, 생략되면 ggplot()에 정의된 데이터 사용\
- stat : 시각화에 적용될 통계요소, 기본값은 'bin'\
- position : 시각화에 적용될 위치요소, 기본값은 'identity'\
- ... : 미적 요소의 설정\
- na.rm : NA 값을 생략할 것인지를 설정하는 논리값\
- show.legend : 범례를 사용할 것인지를 설정하는 논리값\
- inherit.aes : ggplot()에서 설정한 매핑값을 상속받을지 결정하는 논리값
geom_freqpoly()
에서 사용이 가능한 미적 요소는 위치(x,
y), alpha, color, linetype, size, group이다.
geom_freqpoly()
를 사용한 데이터 시각화는 다음과
같다.
## df_취업통계를 ggplot 객체로 생성하고 p_freqpoly에 저장
p_freqpoly <- df_취업통계 |>
ggplot()
bins가 30인 geom_freqpoly는 다음과 같다.
## p_freqpoly에 x축을 '취업률_계'열로 매핑, bins = 30으로 설정한 geom_freqpoly 레이어를 생성
p_freqpoly +
geom_freqpoly(aes(x = 취업률_계), bins = 30)
stat이 density인 geom_freqpoly는 다음과 같다.
## p_freqpoly에 x축을 '취업률_계'열로 매핑, bins = 30으로 설정하는데 통계요소를 'density'로 설정한 geom_freqpoly 레이어를 생성
p_freqpoly +
geom_freqpoly(aes(x = 취업률_계), stat = 'density', bins = 30)
binwidth가 10인 geom_freqpoly는 다음과 같다.
## p_freqpoly에 x축을 '취업률_계'열로 매핑, binwidth = 10으로 설정한 geom_freqpoly 레이어를 생성
p_freqpoly +
geom_freqpoly(aes(x = 취업률_계), binwidth = 10, rm.na = TRUE)
binwidth가 10인 geom_freqpoly
미적 요소를 설정한 geom_freqpoly는 다음과 같다.
## p_freqpoly에 x축을 '취업률_계'열로 매핑, binwidth = 10으로 설정하고 미적 요소를 설정한 geom_freqpoly 레이어를 생성
p_freqpoly +
geom_freqpoly(aes(x = 취업률_계), binwidth = 10, color = 'red', linetype = 2)
미적 요소를 설정한 geom_freqpoly
group과 미적 요소를 매핑한 geom_freqpoly는 다음과 같다.
## p_freqpoly에 x축을 '취업률_계'열로 매핑, group과 color를 과정구분으로 매핑, binwidth = 10으로 설정한 geom_freqpoly 레이어를 생성
p_freqpoly +
geom_freqpoly(aes(x = 취업률_계, group = 과정구분, color = 과정구분), binwidth = 10, linetype = 2)
group과 미적 요소를 매핑한 geom_freqpoly
'ggplot2 > ggplot2의 기초' 카테고리의 다른 글
ggplot2의 기하요소 - geom_bar() (0) | 2023.02.25 |
---|---|
ggplot2의 기하요소 - geom_density() (0) | 2023.02.23 |
ggplot2의 기하요소 - geom_histogram() (0) | 2023.02.17 |
ggplot2의 미적요소 - label & group (0) | 2023.02.15 |
ggplot2의 미적요소 - size & shape (0) | 2023.02.12 |
댓글