GGPLOT TIME SERIES PLOT 시간도표 time plot 개요 시계열 데이터를 시간 흐름(x-축)에 따라 관측값(y-축)을 2차원 그래프에 표현 예제 데이터 : 코스피 지수, 삼상전자 주가 데이터 plot() 함수 이용하여 시계열 데이터 그리기 야후로부터 주가, 코스피 지수를 크롤링 Crawling 하면 날짜는 행 이름(row name) 형식(변수명이 아님) 으로 들어가 있고 시작가 open, 당일 최고가, 최저가, 종가, 거래량, 장마감 후 가격 이 있음 library(quantmod) today<-Sys.Date() #오늘 날짜 #야후 금융: https://finance.yahoo.com/ kospi <- getSymbols("^KS11",src='yahoo', from='2018-01-01', to='2018-05-15', auto.assign = F) #코스피 names(kospi);dim(kospi); head(kospi,3) stock.ss <- getSymbols("005930.KS",src='yahoo', from=today-200, to=today, auto.assign = F) #삼성전자 주가 (120일전 주가) names(stock.ss);dim(stock.ss); head(stock.ss,3) 한남대학교 통계학과 권세혁교수 ( ) 1
5
Embed
시간도표 time plot 개요wolfpack.hnu.ac.kr/Stat_Notes/softwares/about_R/GGPLOT... · 2018-05-17 · GGPLOT TIME SERIES PLOT 시간도표 time plot 개요 시계열 데이터를
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
GGPLOT TIME SERIES PLOT
시간도표 time plot 개요
시계열 데이터를 시간 흐름(x-축)에 따라 관측값(y-축)을 2차원 그래프에 표현
예제 데이터 : 코스피 지수, 삼상전자 주가 데이터
plot() 함수 이용하여 시계열 데이터 그리기
야후로부터 주가, 코스피 지수를 크롤링 Crawling 하면 날짜는 행 이름(row name) 형식(변수명이 아님)으로 들어가 있고 시작가 open, 당일 최고가, 최저가, 종가, 거래량, 장마감 후 가격 이 있음
as.xts() 함수 : 데이터를 시계열 데이터로 만들어 주어야, cbind() 함수에 의해 날짜별로 두 시계열 데이터가 결합된다. 시계열 데이터(행 이름에 날짜가 있는 경우에만 cbind() 사용하면 날짜별로 결합, 그렇지 않으면 위치별로 저장되어 위치 기준 결합되어 날짜 결합이 불가능하다.
#merge two time series data kospi.ss<-cbind(as.xts(kospi),as.xts(stock.ss)) head(kospi.ss,5); tail(kospi.ss,5) names(kospi.ss)