-1

I want to plot a raster with custom color range in ggplot but failed to create color palette with colors and raster values. enter image description here

How can I customize color palette like this? please help me with some reference or codes. I can't write the code for plotting with this type of range.

here is the information of the values and colors in rgba.

$Band_index
[1] 1

$color
$color[[1]]
$color[[1]]$value
[1] "-11.075455892653693"

$color[[1]]$r
[1] 0

$color[[1]]$g
[1] 0

$color[[1]]$b
[1] 255

$color[[1]]$a
[1] 255


$color[[2]]
$color[[2]]$value
[1] "-10.11992481776646"

$color[[2]]$r
[1] 102

$color[[2]]$g
[1] 153

$color[[2]]$b
[1] 0

$color[[2]]$a
[1] 255


$color[[3]]
$color[[3]]$value
[1] "4.816534615997083"

$color[[3]]$r
[1] 102

$color[[3]]$g
[1] 102

$color[[3]]$b
[1] 0

$color[[3]]$a
[1] 255


$color[[4]]
$color[[4]]$value
[1] "64.4114990234375"

$color[[4]]$r
[1] 255

$color[[4]]$g
[1] 255

$color[[4]]$b
[1] 255

$color[[4]]$a
[1] 255
  • Interesting colour definitions, Subhadip, but where's the code to produce the raster? – Limey Jun 10 '20 at 08:31
  • I downloaded the raster. It is not crated by me. @Limey – Subhadip Datta Jun 10 '20 at 08:58
  • Ok, I understand your question Limey. I just listed out values and colors in rgba as list for this raster, I downloaded. I just created the list for simplify my work to plot. and the color palette in my question are as legend of a software ESA SNAP. I want to plot same way as the software did. – Subhadip Datta Jun 10 '20 at 09:07
  • SO isn't a code writing service, Subhadip. We're here to help you solve problems in the code you are trying to write. To do that, we need a simple, self-contained example. [This post](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) will provide some guidance. In this case, we will need some toy input data, some code, and any error or warning messages you get. You've already given us the intended output, so that's a start! – Limey Jun 10 '20 at 09:16
  • Ok, I can understand you Limey. But I just have problem with the color palette. Can you just say me can I generate this type of color palette in R plot? Forgot about the raster. Just think about any kind of plot with colors. – Subhadip Datta Jun 10 '20 at 09:33

1 Answers1

0

From this page,

ggplot(faithfuld, aes(waiting, eruptions)) + geom_raster(aes(fill = density))

gives

enter image description here

Limey
  • 10,234
  • 2
  • 12
  • 32