From MarginTale |

How do you attack the problem? Looking at the example output above:

- We facet_grid by "months" and "years"
- The data itself is plotted by "week of month" and "day of week" and coloured according to the value of interest

So, given a time series we just have to fiddle with time indexes to create a data.frame containing the time series as well as per observation the corresponding "month", "year", "week of month", "day of week". The rest is then a one-liner of code with Hadley's wonderful ggplot2 system.

The following code contains step by step comments:

The following code contains step by step comments:

It should be easy to wrap into a function and I hope its useful.

Hello,

ReplyDeletethanks for this very interesting post!

I'm fairly new to R so I was hopping you could help with this: I'm trying to create the same chart but using daily percentage changes instead of close prices. I tried several ways but I couldn't do it. I was wondering if you could help me with this.

Thanks a lot in advance!

Dan.

thx,

Deletequick and dirty, add:

VIX<-dailyReturn(Cl(VIX))

colnames(VIX)<-"VIX.Close"

after the line containing getSymbols

enjoy

Hi,

ReplyDeleteIt is a good post. Just want to simplify few statements using lubridate package, especially where creating month, year and weekday are involved

library(lubridate)

dat$year = year(dat$date)

# using month() in lubridate and set label option to true to get Jan..

dat$month = month(dat$date, label = TRUE, abbr = TRUE)

dat$weekday = wday(dat$date, label = TRUE, abbr = TRUE)

#approximate for week num in month

dat$monthday = mday(dat$date)

dat$monthweek = ceiling(dat$monthday / 7)

Cheers

Krishna

This is very useful. Thanks for posting.

ReplyDeleteWhen I run this on the stock example, as well as data I have available, I'm getting scientific notation in the label on the right (ie. VIX.Close = 2.0e+01 as opposed to 20). Any thoughts on how this could be fixed?

what happens if you add

Deletebreaks=seq(10,80,10)

as a parameter into scale_fill_gradient(...) above?

I'm having the same problem. The Week of the Month axis labels are also in scientific notation. How can I change this?

DeleteNote: using breaks=seq(10,80,10) didn't change it.