ggplot2 - Plot multiple timeseries using ggplot R -



ggplot2 - Plot multiple timeseries using ggplot R -

this question has reply here:

multiple time series in 1 plot 3 answers

i have xts object containing number of timeseries. info looks like:

head(data)

date v1 v2 v3 v4 v5 v6 2014-07-31 na 721 696 na 487 469 2014-08-02 735 752 696 559 505 469 2014-08-04 1502 737 696 757 510 469 2014-08-06 799 722 697 559 487 469 ...

"date" date variable , other variables contain cost developments. automatically plot of series (so v1, v2, v3), without manually inserting names. done using xtsextra, bundle no longer available r3.1.0.

is there way plot these time-series in 1 window using ggplot2? (incl. labeling , different colours)

many thanks!

you can plot multiple line series using group argument ggplot. original dataframe, may need reformat things using melt reshape2 package.

library(ggplot2) library(reshape2) df<-data.frame(date=as.date(c('2014-06-25','2014-06-26','2014-06-27')),v1=rnorm(3),v2=rnorm(3)) newdf<-melt(df,'date') ggplot(newdf,aes(x=date,y=value,group=variable,color=variable) ) + geom_line() +scale_x_date()

r ggplot2 time-series xts

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -