2016-07-26 7 views
-1

XTS 객체가 있는데 ggplot에서 여러 시계열을 그려 봅니다. 같은 플롯에서 여러 개의 시계열을 어떻게 그립니 까? 당신이 어떤 데이터 세트를 제공하지 않기 때문에xts 객체의 ggplot2에있는 여러 시계열

+2

에 오신 것을 환영에 StackOverflow에. 제발, [투어] (http://stackoverflow.com/tour)를 가져다가 무엇을 어떻게 볼 수 있습니까? (http://stackoverflow.com/help/asking). 코드에 관한 질문 인 경우 지금까지 수행 한 작업에 대한 [최소한의 완전하고 검증 가능한 예제] (http://stackoverflow.com/help/mcve)를 제공해주십시오. – user3078414

답변

2

, 나는 AirPassengers 데이터 집합을 사용하여 예시 있습니다 :

library(datasets) 
library(xts) 
library(ggplot2) 
library(broom) 
library(magrittr) 
ap.xts <- as.xts(AirPassengers) 
mseries <- cbind(ap.xts, rollmean(ap.xts,7)) # mseries is a xts object with multiple variables 
names(mseries) <- c("Passengers", "MA_Passengers") # names for the series, otherwise the names are '..1' and '..2' 
index(mseries) <- as.Date(index(mseries)) # to avoid warnings since ggplot scale don't handle yearmon natively 
tidy(mseries) %>% ggplot(aes(x=index,y=value, color=series)) + geom_line() 

multiple xts in ggplot2

관련 문제