Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can <code>panel.level.plot</code> from <code>latticeExtra</code> to add pattern. I think the question as it is asked is a little bit specific. So I try to generalize it. The idea is to give the steps to transform a time series to a calendar heatmap: with 2 patterns (fill color and a shape). We can imagine multiple time series (Close/Open). For example, you can get something like this</p> <p><img src="https://i.stack.imgur.com/9DLjo.png" alt="enter image description here"></p> <p>or like this, using a ggplot2 theme:</p> <p><img src="https://i.stack.imgur.com/CRQCv.png" alt="enter image description here"></p> <p>The function <code>calendarHeat</code> , giving a single time series (dat,value) , transforms data like this :</p> <pre><code> date.seq value dotw woty yr month seq 1 2012-01-01 NA 0 2 2012 1 1 2 2012-01-02 NA 1 2 2012 1 2 3 2012-01-03 NA 2 2 2012 1 3 4 2012-01-04 NA 3 2 2012 1 4 5 2012-01-05 NA 4 2 2012 1 5 6 2012-01-06 NA 5 2 2012 1 6 </code></pre> <p>So I assume that I have data formated like this, otherwise, I extracted from calendarHeat the part of data transformation in a function(see this <a href="https://gist.github.com/agstudy/5013751" rel="noreferrer">gist</a>)</p> <pre><code> dat &lt;- transformdata(stock.data$Date, stock.data$by) </code></pre> <p>Then the calendar is essentially a <code>levelplot</code> with custom <code>sacles</code> , custom <code>theme</code> and custom <code>panel' function</code>.</p> <pre><code>library(latticeExtra) levelplot(value~woty*dotw | yr, data=dat, border = "black", layout = c(1, nyr%%7), col.regions = (calendar.pal(ncolors)), aspect='iso', between = list(x=0, y=c(1,1)), strip=TRUE, panel = function(...) { panel.levelplot(...) calendar.division(...) panel.levelplot.points(...,na.rm=T, col='blue',alpha=0.5, ## you can play with cex and pch here to get the pattern you ## like cex =dat$value/max(dat$value,na.rm=T)*3 pch=ifelse(is.na(dat$value),NA,20), type = c("p")) }, scales= scales, xlim =extendrange(dat$woty,f=0.01), ylim=extendrange(dat$dotw,f=0.1), cuts= ncolors - 1, colorkey= list(col = calendar.pal(ncolors), width = 0.6, height = 0.5), subscripts=TRUE, par.settings = calendar.theme) </code></pre> <p>Where the scales are:</p> <pre><code> scales = list( x = list( at= c(seq(2.9, 52, by=4.42)), labels = month.abb, alternating = c(1, rep(0, (nyr-1))), tck=0, cex =1), y=list( at = c(0, 1, 2, 3, 4, 5, 6), labels = c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"), alternating = 1, cex =1, tck=0)) </code></pre> <p>And the theme is setting as :</p> <pre><code> calendar.theme &lt;- list( xlab=NULL,ylab=NULL, strip.background = list(col = "transparent"), strip.border = list(col = "transparent"), axis.line = list(col="transparent"), par.strip.text=list(cex=2)) </code></pre> <p>The panel function uses a function caelendar.division. In fact, the division of the grid(month black countour) is very long and is done using <code>grid</code> package in the hard way (panel focus...). I change it a little bit, and now I call it in the lattice panel function: <a href="https://gist.github.com/agstudy/5013606" rel="noreferrer">caelendar.division</a>.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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