Search code examples
rheatmapcolor-palette

Custom color scale for filled.contour heatmap with base R


I have this kind of color palette that I want to use

palette <- colorRampPalette(c("darkblue", "blue", "lightblue1",
                                "green", "yellow", "red", "darkred"))

Illustration how my graphs look at the moment enter image description here

I have used filled.contour() to plot this graph with some modifications.

Here's a part of the code that makes somewhat similar graph

load("workspace.RData")
library(lubridate)

breaks <- "2 hours"
palette <- colorRampPalette(c("darkblue", "blue", "lightblue1",
                              "green", "yellow", "red", "darkred"))
f <- function(x) as.POSIXct(levels(cut(x, breaks)))

filled.contour(x = data$Time,
               y = log10(channels),
               z = df,
               color.palette = palette,
               plot.axes = axis(1, at = f(data$Time),
                                labels = format(f(data$Time), "%H:%M")))

by using data, channels and df from my workspace made with save.image().

Now the function is making the color legend on the right look like that by default. I would like to specify myself that dark blue corresponds to 0 and dark red corresponds to some user defined value for example 20 million.

I want this because if I was to compare the graph of this data with graph of some other data, they would have exactly the same color legend.

Tell me if I need to provide more information or anything.

EDIT:

Provided the data from my workspace as workspace.RData file.


Solution

  • levels (and nlevels) parameters seem to do the job just fine... I feel stupid.