이민호님의 깃허브( http://lumiamitie.github.io/ )를 참고하여 실습
ggplot2 뿐만 아니라 유용한 패키지가 많이 소개 되어있으니 참고하면 좋을듯
ggplot2는
1. Layer
2. Sclae
3. Coordinate system
4. facetting specification
5. Guides
5가지로 요인으로 구성된다.
그중 첫번째 요인인 Layer는 1) Data 2) Mapping 3) Statiscal Transformation 4) Geometric Object 5) Position으로 나뉜다.
이민호님의 깃허브를 보면 자세하게 정리되어있으니 이를 참조할 것( http://lumiamitie.github.io )
요즘 실습 데이터로 쓰고 있는 코비의 슛 데이터를 불러온다.
setwd("C:/Users/user/Desktop/kob")
rd=read.csv("data.csv",header=T)
ggplot() +
layer(data=rd,
mapping = aes(x=loc_x, y=loc_y, colour=combined_shot_type),
geom='point',
stat='identity',
position='identity')
점프샷이 압도적으로 많으니 점프샷은 지운다
rd2=subset(rd,combined_shot_type!='Jump Shot')
ggplot() +
layer(data=rd2,
mapping = aes(x=loc_x, y=loc_y, colour=combined_shot_type),
geom='point',
stat='identity',
position='identity')
뱅크샷은 보통 중앙에서 많이 쏠줄 알았는데 그렇지 않았음
외곽 특히 왼쪽 외곽에서 슛을 많이 하는 것을 볼 수 있다.
ggplot() +
layer(data=rd2,
mapping = aes(x=loc_x, y=loc_y, colour=combined_shot_type),
geom='point',
stat='identity',
position='identity')
그런데 코드가 좀 길다. stat, position의 경우 'identity'라는 default값이 설정되어 있다.
이럴때는!
ggplot()+
geom_point(data=rd2, aes(x=loc_x, y=loc_y, colour=combined_shot_type))
로 짧게 표현 할 수 있다. 즉, 자주 사용하는 그래프 개형은 함수로 만들어져 있는듯
shortcut 함수들은 google에 물어볼것
다음엔
ggplot2의 layer를 제외한 나머지 요인들을 정리 할 것!!
'Data Science' 카테고리의 다른 글
Neural networks (0) | 2017.03.13 |
---|---|
Random forest (0) | 2017.03.05 |
qplot (0) | 2017.02.05 |
dplyr package (1) | 2016.06.12 |
온라인 판매자 시뮬레이션(Monte-Carlo Simulation) (1) | 2016.01.03 |