0

I found very useful and complex figure from below link but the displays daily closing price by year for 4 years but my target figure is say 30 years daily closing price so it's too long and should be too messy for the readers.

Most underused data visualization

Instead, I want to transform the daily data as quarterly (on y axis) for 6 consecutive years (on x axis) but I can not transform year to 6 years on the following facet

facet_wrap(~ year, ncol = 1)

as I a new to the ggplot2.

Can somebody have a look and give me the solution?

Many thanks

Community
  • 1
  • 1

1 Answers1

0

The facet_wrap gives you the individual plots for each year. From your description, you want a single plot, something like

# tranforming data from linked question to get quarters (not perfect)
require(dplyr)
stock.sum <- stock.data %>% filter(wday == 1, week %% 13 == 1, week < 52) %>%
    mutate(quarter = (week %/% 13) + 1)

# plot! year on x, quarter on y (seems backwards to me)
ggplot(stock.sum, aes(x = factor(year), y = quarter, fill = Adj.Close)) +
    geom_tile(colour = "white") +
    scale_fill_gradientn(colours = c("#D61818","#FFAE63","#FFFFBD","#B5E384"))
# just leave out the facet_wrap()
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
  • This is definitely big improvement. However the date on the original code date start from 2006 but my target is 30 years backward from today. If we assume 10 years frequency for x axis, then we will have 3 layers in y axis on final figure ( or 3 floors * 4 quarters * 10 years ). Please help me out. – Jung Soo Park Sep 28 '14 at 10:33
  • The only data I see is the data from the linked question. If your data looks different, post it! At least post `dput(head(my_data))`. – Gregor Thomas Sep 28 '14 at 16:58
  • @JungSooPark I don't understand if your problem is transforming data AND plotting, or just plotting. And I don't know what `floor` is, when you say you have "3 floors". Sharing data will help. – Gregor Thomas Sep 28 '14 at 16:59
  • If we modify the stock name and periods on the original code, then we can get the 30 years data. stock <- "IBM" start.date <- "1981-01-01" end.date <- "2010-12-31" – Jung Soo Park Sep 30 '14 at 03:07
  • The original heap map has 4 layers (floors) of 7days*12month heap map and mine has 3 layers (floors) of 4 quarters*10years heat map. – Jung Soo Park Sep 30 '14 at 03:11