简体   繁体   中英

Incorporating colorspace into diverge0?

I am trying to plot a rasterstack with a color scheme of red to blue with white in the centre. This is my code:

plot2<-diverge0(rasterstack, ramp='RdBu')

But when the stack is plotted, the colors are very light in shade. I would like to incorporate the code of 'colorspace' of :

darken(col, amount = 0.1, space = "combined")

How can I make the color palette obtained from diverge0 to be darker?

The below code is what I currently came up with

plot2<-diverge0(rasterstack, ramp='RdBu',darker=0.4)

which results in an error.

It is unclear where the diverge0() function comes from. If it is the one from https://gist.github.com/johnbaums/306e4b7e69c87b1826db , then it seems that you can do (disclaimer: untested):

diverge0(rasterstack,
  ramp = colorRampPalette(
    darken(brewer.pal(11, "RdBu"), amount = 0.1, space = "combined")
  )
)

Note that rather than going through RColorBrewer first and then tweaking the result afterwards you could also play with the parameters of divergingx_hcl(11, "RdBu") or diverging_hcl(11, "Blue-Red 3", rev = TRUE) . For example, you could replace the code from the third code line above ( darken(...) ) with either

divergingx_hcl(11, palette = "RdBu", l2 = 85, cmax1 = 90)

or

diverging_hcl(11, "Blue-Red 3", rev = TRUE, l2 = 85)

Both make the luminance of the central gray somewhat darker ( l2 = 85 ) with the former also limiting the maximum chroma (which is always lower with the latter anyway).

In the latter case you can also register your custom palette with a new name, eg,

diverging_hcl(11, "Blue-Red 3", l2 = 85, register = "Dark Blue-Red")
diverging_hcl(11, "Dark Blue-Red", rev = TRUE)
## [1] "#5F1415" "#953535" "#BB6060" "#CF8D8E" "#D9B6B6" "#D4D4D4" "#B6BED7"
## [8] "#8C9ECE" "#577AC1" "#1554A4" "#002F70"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM