Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's not very concise, but I think this should do what you need.</p> <p>You didn't provide a data set, so I just made some up. Also, the <code>LtoM</code> and <code>MtoH</code> functions are not included in any R package I could find, so I did a quick Google search and found them <a href="http://quantcorner.wordpress.com/2013/11/02/creating-a-heatmap-to-visualize-returns-with-r-ggplot2/" rel="noreferrer">here</a></p> <p>The following code produces a plot <code>hm2</code> with facets to make the "Mean Return" row at the bottom:</p> <pre><code>require(reshape2) require(ggplot2) # Random data set.seed(100) casted = data.frame(Var1 = rep(1985:2013, times=12), Var2 = rep(month.abb, each=29), return = rnorm(12*29, 0, 9)) molten = melt(casted, id.vars = c("Var1", "Var2")) LtoM &lt;-colorRampPalette(c('red', 'yellow' )) Mid &lt;- "snow3" MtoH &lt;-colorRampPalette(c('lightgreen', 'darkgreen')) # Averages monthly.avg = cbind(Var1 = rep("Mean", 12), dcast(molten, Var2 ~ ., mean)) colnames(monthly.avg)[3] = "Mean" molten2 = merge(molten, melt(monthly.avg), all.x = TRUE, all.y = TRUE) # New plot hm2 = ggplot(data = molten2, aes(x = factor(Var2, levels = month.abb), y=Var1, fill=value)) + geom_raster() + scale_fill_gradient2(low=LtoM(100), mid=Mid, high=MtoH(100)) + labs(fill='% Return') + geom_text(aes(label=paste(sprintf("%.1f %%", value))), size = 4) + xlab(label = NULL) + ylab(label = NULL) + theme_bw() + theme(axis.text.x = element_text(size = 10, hjust = 0, vjust = 0.4, angle=90)) + facet_grid(variable ~ ., scales = "free_y", space = "free_y") + # grid layout theme(strip.background = element_rect(colour = 'NA', fill = 'NA'), strip.text.y = element_text(colour = 'white')) # remove facet labels </code></pre> <p>which gives the following plot:</p> <p><img src="https://i.stack.imgur.com/tk6Z0.jpg" alt="Plot with Mean Row"></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.
    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