R/ggplot: Reuse color key for multiple heat maps


I am generating multiple heatmaps to be plotted as an animation. I want to reuse the color keys for different heatmaps to show the change with time. Currently the key is being reset for each heatmap.

Heatmap1: (<a href="http://i.imgur.com/iPIDY82.png" rel="nofollow">http://i.imgur.com/iPIDY82.png</a>) Heatmap2: (<a href="http://i.imgur.com/GvNfQal.png" rel="nofollow">http://i.imgur.com/GvNfQal.png</a>)

I would like the "total range" to be the same in both heatmaps. So Heatmap1 above should have a net "lighter" color.

The code I have at present is as follows:

mat <- matrix(unlist(row), ncol=4, byrow=TRUE) matm <- melt (mat) p <- ggplot (data=matm) + geom_tile (aes(x=X1, y=X2, fill=value), color="white") + scale_fill_gradient (low="steelblue1", high="steelblue4")

row has data for each of the 16 cells. I convert it to a matrix, and then plot the same. But different rows have different ranges, and the range is reset each time.

I have tried the following modifications:

[1] Add breaks to the scale_fill

scale_fill_gradient (low="steelblue1", high="steelblue4",breaks=seq(3,6.4,by=0.05))

[2] Cut the data into factors and add breaks to the scale_fill

row_cut <- cut (as.numeric(row), breaks=seq(3,6.4,by=0.05), right=FALSE) mat <- matrix(unlist(row_cut), ncol=4, byrow=TRUE) matm <- melt (mat) p <- ggplot (data=matm) + geom_tile (aes(x=X1, y=X2, fill=value), color="white") + scale_fill_brewer(palette = "Blues","intensity", breaks=seq(3,6.4,by=0.05))

But neither of the modifications helps.

(Aside: When I add breaks to scale_fill the legend is missing in the plots)


Use the limits parameter:

scale_fill_gradient(..., limits=c(3, 6.4))


  • Inspect Element Using System.Windows.Forms.WebBrowser
  • set palette color to blue in gnuplot
  • XSLT 1.0: copy everything except certain nodes according to value and variable
  • Creating BackgroundSubtractorMOG2 in Android by OpenCV 3.0 RC1
  • How to transform Byte[](decoded as PNG or JPG) to Tensorflows Tensor
  • Runtime error in UVA Online Judge [closed]
  • Pointer vs Reference difference when passing Eigen objects as arguments
  • Msvcr71.dll Msvcp71.dll missing
  • Passing information to server-side function in a Google Docs Add On
  • Change device language on Android 6.0 (Android M)
  • Not able to display correct data in table -AngularJS
  • SQL: Getting the physical size of a subset of a table
  • What's the syntax to inherit documentation from another indexer?
  • How to log in to an HTTPS website with Jsoup?
  • pip in virtualenv gets ConnectTimeoutError
  • quiver not drawing arrows just lots of blue, matlab
  • how does System.Web.HttpRequest::PathInfo work?
  • Marklogic : Query response time is very high
  • Swing - Get new component under mouseReleased
  • How to clear text inside text field when radio button is select
  • Is there any way to access browser form field suggestions from JavaScript?
  • Launch Runnable Jar from Web Start
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • Get object from AWS S3 as a stream
  • Cross-Platform Protobuf Serialization
  • Validaiting emails with Net.Mail MailAddress
  • VBA Convert delimiter text file to Excel
  • How do I use the BLAS library provided by MATLAB?
  • jQuery tmpl and DataLink beta
  • Do I've to free mysql result after storing it?
  • File upload with ng-file-upload throwing error
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • How can I remove ASP.NET Designer.cs files?
  • costura.fody for a dll that references another dll
  • Reading document lines to the user (python)
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal