geom_multi_raster {plothelper} | R Documentation |
Geom Layer for Drawing Multiple Rasters
Description
Unlike annotation_raster
which
draws only 1 raster, this layer
draws one or more rasters at the same time.
The data must be a tbl object created by
package tibble and the reason is that,
as we must give each rectangle a
vector of colors, the column that
contains these vectors of colors must
be a list rather than a vector. A list can
be a column for tbl object, not for
a normal data frame. See examples.
Accepted properties are:
(1)
xmin
.(2)
xmax
.(3)
ymin
.(4)
ymax
.(5)
raster
. a list with 1 or more rasters. If you have only 1 raster, you also have to put it into a list. Each raster should be a matrix, a raster object, a character vector or a magick object read into R bymagick::image_read
. You can also use a data frame created by package tibble to combinexmin, xmax, ymin, ymax, raster
.(6)
interpolate
. It is the same as that inannotation_raster
except that the default value is TRUE. It can be used either inside or outside theaes(...)
function. Its length must be either 1 or the same as the number of rasters.(7)
flip
. The default is FALSE. You only need to use TRUE when you usecoord_flip
. Used outside theaes(...)
function.
Usage
geom_multi_raster(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
flip = FALSE,
...
)
Arguments
mapping |
aes mapping. |
data |
data. It should be a tbl object. |
stat |
stat. |
position |
position. |
na.rm |
logical, whether to remove NA values. |
show.legend |
This will not be used because the layer does not create any legend. |
inherit.aes |
logical, whether to inherit aes from ggplot(). |
flip |
see description. |
... |
additional parameters. |
Examples
# Example 1: use vectors and a list.
mycolor=list(
c1=matrix(c("red", "blue", "green", "yellow"), nrow=2),
c2=matrix(c("green", "yellow")),
c3=matrix(c("purple", "red")))
xmin=1: 3
xmax=(1: 3)+0.8
ymin=c(0, 1, 2)
ymax=c(1, 3, 5)
ggplot()+
geom_multi_raster(aes(xmin=xmin, xmax=xmax,
ymin=ymin, ymax=ymax, raster=mycolor))
#
# Example 2: the same as example 1
# except flip=TRUE.
ggplot()+coord_flip()+
geom_multi_raster(aes(xmin=xmin, xmax=xmax,
ymin=ymin, ymax=ymax, raster=mycolor), flip=TRUE)