0

I have a raster image that I try to plot using rasterVis package in BuRdTheme. But I find the colors to be dull.

enter image description here

However, what I need is something like following. How can I create this desired pallete in raster or rasterVis or if any other package that would be appropriate? enter image description here

I tried creating new palette with rasterTheme

rainbTheme5 <- rasterTheme(region = rev(rainbow(n = 5)))
levelplot(r,par.settings=rainbTheme5)

What I get is

enter image description here

The histogram of the image looks like enter image description here

rar
  • 894
  • 1
  • 9
  • 24
  • This isn't just the palette, but the way values are mapped to palette colours. You might want to do some sort of non-linear transform of your data. What does a histogram of the values look like? – Spacedman Aug 25 '16 at 07:31
  • 1
    Here are some [more perceptually uniform color palettes](https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html) that you might find visually interesting. The rainbow/spectral style will create some artifacts in the visualization. – Will Cornwell Aug 25 '16 at 07:50

2 Answers2

0

You've got some pixels down at about 305 (which I guess is blue) so most of your pixels are over 320 and so all in the brown/red end of your palette.

What you might want is a palette that changes over the peak in your data. You can do this by creating a palette that starts with a bunch of colours for the low values. For example:

> rep(rev(rainbow(n=5)),c(5,1,1,1,1))
[1] "#CC00FFFF" "#CC00FFFF" "#CC00FFFF" "#CC00FFFF" "#CC00FFFF" "#0066FFFF"
[7] "#00FF66FF" "#CCFF00FF" "#FF0000FF"

That has 9 colours, and the first five are identical. In this case, 5/9 of the range of the data would all be that colour, and the highest 4/9 of the dataset would be coloured by the full range of the data. Since your peak spans about that amount, you'll get the effect you are after. Adjust the palette to suit.

Note that you should always ask what question any graphic is trying to answer, and adjust colours/scales etc to help answer that question, rather than just trying to make it not look "dull", unless this is for the wall of a gallery.

Spacedman
  • 92,590
  • 12
  • 140
  • 224
  • What I meant by "dull" was the tone of red and blue in BuRd Theme in comparison to ` rainbow `. I did not know how to play with colors in palette. Thanks! – rar Aug 25 '16 at 09:48
0

Finally I could find what I was looking for:

myTheme <- rasterTheme(region = rep(rev(rev(colorRamps::matlab.like(n=12))),c(1,1,1,1,1,1,1,1,1,1,1,1)))

Using levelplot and using levelplot with customised theme

enter image description hereenter image description here

rar
  • 894
  • 1
  • 9
  • 24