Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We can use ggplot2's <code>scale_shape_manual</code> to get us shapes that appear close to shading, and we can plot these over the grey heatmap.<br> <em>Note: This was adapted from @Jay's comments in <a href="http://blog.revolutionanalytics.com/2009/11/charting-time-series-as-calendar-heat-maps-in-r.html" rel="noreferrer">the original blog</a> posting for the calendar heatmap</em></p> <pre><code># PACKAGES library(ggplot2) library(data.table) # Transofrm data stock.data &lt;- transform(stock.data, week = as.POSIXlt(Date)$yday %/% 7 + 1, month = as.POSIXlt(Date)$mon + 1, wday = factor(as.POSIXlt(Date)$wday, levels=0:6, labels=levels(weekdays(1, abb=FALSE)), ordered=TRUE), year = as.POSIXlt(Date)$year + 1900) # find when the months change # Not used, but could be stock.data$mchng &lt;- as.logical(c(0, diff(stock.data$month))) # we need dummy data for Sunday / Saturday to be included. # These added rows will not be plotted due to their NA values dummy &lt;- as.data.frame(stock.data[1:2, ]) dummy[, -which(names(dummy) %in% c("wday", "year"))] &lt;- NA dummy[, "wday"] &lt;- weekdays(2:3, FALSE) dummy[, "mchng"] &lt;- TRUE rbind(dummy, stock.data) -&gt; stock.data # convert the continuous var to a categorical var stock.data$Adj.Disc &lt;- cut(stock.data$Adj.Close, b = 6, labels = F) # vals is the greyscale tones used for the outer monthly borders vals &lt;- gray(c(.2, .5)) # PLOT # Expected warning due to dummy variable with NA's: # Warning message: # Removed 2 rows containing missing values (geom_point). ggplot(stock.data) + aes(week, wday, fill=as.factor(Adj.Disc), shape=as.factor(Adj.Disc), color=as.factor(month %% 2)) + geom_tile(linetype=1, size=1.8) + geom_tile(linetype=6, size=0.4, color="white") + scale_color_manual(values=vals) + geom_point(aes(alpha=0.2), color="black") + scale_fill_grey(start=0, end=0.9) + scale_shape_manual(values=c(2, 3, 4, 12, 14, 8)) + theme(legend.position="none") + labs(y="Day of the Week") + facet_wrap(~ year, ncol = 1) </code></pre> <p><img src="https://i.stack.imgur.com/yfYDe.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload