Plot rectangles colored by a quantitative attribute and overlay on an RGB image
Source:R/utils_shp.R
plot_index_shp.Rd
This function plots rectangles on top of an RGB image, where each rectangle
is colored based on a quantitative variable. The quantitative variable is
specified in the attribute
argument and should be present in the
object_index
of the object
computed using analyze_objects_shp()
. The
rectangles are colored using a color scale.
Arguments
- object
An object computed with
analyze_objects_shp()
.- attribute
The name of the quantitative variable in the
object_index
to be used for coloring the rectangles.- r, g, b
The layer for the Red, Green and Blue band, respectively. Defaults to
1
,2
, and3
.- color
A vector of two colors to be used for the color scale.
- viewer
The viewer option. If not provided, the value is retrieved using
get_pliman_viewer()
. This option controls the type of viewer to use for interactive plotting. The available options are"base"
and"mapview"
. If set to "base", the base R graphics system is used for interactive plotting. If set to "mapview", the mapview package is used. To set this argument globally for all functions in the package, you can use theset_pliman_viewer()
function. For example, you can runset_pliman_viewer("mapview")
to set the viewer option to "mapview" for all functions.- max_pixels
integer > 0. Maximum number of cells to plot the index. If
max_pixels < npixels(img)
, downsampling is performed before plotting the index. Using a large number of pixels may slow down the plotting time.- downsample
integer; for each dimension the number of pixels/lines/bands etc that will be skipped; Defaults to
NULL
, which will find the best downsampling factor to approximate themax_pixels
value.- downsample_fun
function; if given, downsampling will apply
downsample_fun``
to each of the the subtiles.- alpha
The transparency level of the rectangles' color (between 0 and 1).
- legend.position
The position of the color legend, either
"bottom"
or"right"
.- na.color
The color to be used for rectangles with missing values in the quantitative variable.
- classes
The number of classes in the color scale.
- round
The number of decimal places to round the legend values.
- horiz
Logical, whether the legend should be horizontal (
TRUE
) or vertical (FALSE
).
Value
The function plots rectangles colored by the specified quantitative variable on top of the RGB image and shows the continuous color legend outside the plot.
Examples
if(interactive()){
library(pliman)
# Computes the DGCI index for each flax leaf
flax <- image_pliman("flax_leaves.jpg", plot =TRUE)
res <-
analyze_objects_shp(flax,
buffer_x = 0.2,
buffer_y = 0.2,
nrow = 3,
ncol = 5,
plot = FALSE,
object_index = "DGCI")
plot(res$final_image)
plot_index_shp(res)
}