[R] graph together 4 series after HP filter

Giorgio Garziano giorgio.garziano at ericsson.com
Tue Sep 6 17:11:49 CEST 2016


Hi Sebastian,

here are examples with ggplot2 and basic graphic.

http://stackoverflow.com/questions/3777174/plotting-two-variables-as-lines-using-ggplot2-on-the-same-graph

http://stackoverflow.com/questions/17150183/r-plot-multiple-lines-in-one-graph


You may also impress your audience by using iterative graphs as provided by dygraphs package.

https://blog.rstudio.org/2015/04/14/interactive-time-series-with-dygraphs/

You have to convert your xts objects starting from your ts ones.

An example:

getSymbols("AAPL", src = "yahoo", from = as.Date("2013-07-01"), to = as.Date("2016-06-30"))
getSymbols("YHOO", src = "yahoo", from = as.Date("2013-07-01"), to = as.Date("2016-06-30"))
getSymbols("CPHD", src = "yahoo", from = as.Date("2013-07-01"), to = as.Date("2016-06-30"))
getSymbols("EMC", src = "yahoo", from = as.Date("2013-07-01"), to = as.Date("2016-06-30"))
AAPL.xts <- Ad(AAPL)
YHOO.xts <- Ad(YHOO)
CPHD.xts <- Ad(CPHD)
EMC.xts <- Ad(EMC)

df <- data.frame(AAPL.xts, YHOO.xts, CPHD.xts, EMC.xts)
head(df)

library(dygraphs)
dygraph(df)

--

Best,

GG





	[[alternative HTML version deleted]]



More information about the R-help mailing list