Display color raster with plet()
Closed this issue · 12 comments
Thanks. This now works as expected.
By my example works (at least for me). You divide the raster by 100 and then it is no longer an RGB image.
You divide the raster by 100 and then it is no longer an RGB image.
stretch="lin"
is not supposed to take care of that, as it does in plotRGB()?
With plotRGB
there is no doubt that we are dealing with an RGB raster. With plot
and plet
that needs to be explicit.
For example compare the two plots
library(terra)
s <- rast(system.file("ex/logo.tif", package="terra"))
plot(s)
plot(s/100)
I see, but
> class(s)
[1] "SpatRaster"
attr(,"package")
[1] "terra"
> class(s/100)
[1] "SpatRaster"
attr(,"package")
[1] "terra"
still think that stretch="lin" should transform the object to the (0,255) range, and thus I would expect
plot(r/100, stretch="lin)
to be the same colors as
plot(r, stretch="lin")
But you must have your reasons.
What I would like to know is, how should we display r/100 to have the same colors as plot(r) ?
Just plotRGB(r/100, stretch="lin)
?
What about plet()? there is no pleRGB()
A SpatRaster looses its RGB channels if you do an arithmetic operation
library(terra)
s <- rast(system.file("ex/logo.tif", package="terra"))
RGB(s)
RGB(s/100)
You can set the channels when needed
r <- s/100
RGB(r) <- 1:3
# or set.RGB(r, 1:3)
plot(r, stretch="lin")
To make that more compact, you can now also do
r <- s/100
plot(RGB(r, 1:3), stretch="lin")
There is no pletRGB
because my thinking is that you can accomplish the same with the above at the expense of a pair of parentheses. In stead of pletRGB()
you now have plet(RGB())
Excellent!