Domanda

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: (http://i.imgur.com/iPIDY82.png) Heatmap2: (http://i.imgur.com/GvNfQal.png)

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)

È stato utile?

Soluzione

Use the limits parameter:

scale_fill_gradient(..., limits=c(3, 6.4))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top