Learn R Programming

gapfill (version 0.9.6-1)

Image: Image Panels

Description

Creates an image panel to visualize data in 4, 3 or 2 dimensional arrays (e.g., space-time data). The function returns a ggplot2 object, which can be modified using ggplot2 (and/or grid) syntax.

Usage

Image(
  x = NULL,
  zlim = range(x, na.rm = TRUE),
  col = fields::tim.colors(1000),
  theme = TRUE,
  guides = TRUE,
  na.value = "black",
  panelsByrow = TRUE,
  asRaster = TRUE,
  xlab = "",
  ylab = "",
  colbarTitle = "",
  ...
)

Arguments

x

Numeric array with 4, 3, or 2 dimensions containing the data to be plotted.

zlim

Numeric vector of length 2. Gives the upper and lower bound of the plotted values.

col

Vector of colors.

theme

Logical vector of length one. Should the ggplot2 theme be modified?

guides

Logical vector of length one. Should ggplot2 guides be modified?

na.value

Vector of length one. The color to be used for NA values.

panelsByrow

Logical vector of length one. Indicates the ordering of the panels.

asRaster

Logical vector of length one. If TRUE, the ordering of the pixel within images is similar to the plot method of the raster package. Otherwise, the ordering is similar to image.

xlab

Character vector (or expression) of length one giving the x-axis label.

ylab

Character vector (or expression) of length one giving the y-axis label.

colbarTitle

Character vector (or expression) of length one giving the colorbar label.

...

Additional arguments are passed to ggplot.

Value

Object (plot) of class c("gg", "ggplot2").

See Also

ndvi, ggplot2.

Examples

Run this code
# NOT RUN {
library("abind")
t1 <- array(rep(c(1,0), each = 5), c(5,5))
t1[5,3] <- 2 
t2 <- abind(t1, t1, along = 3)
t3 <- abind(t2, t2, along = 4)
Image(t1)
Image(t2)
Image(t3)

# }
# NOT RUN {
Image(ndvi)

p1 <- Image(ndvi, colbarTitle = "NDVI", xlab = "Year", ylab = "DOY",
            panelsByrow  = FALSE)
p1

p2 <- Image(ndvi[,,3,2], na.value = "white", colbarTitle = "NDVI") +
      theme(strip.text.x = element_blank(),
            strip.text.y = element_blank(),
            panel.border = element_rect(fill = NA, size = 1))
p2

## place modified color bar left
p2 + guides(fill = guide_colorbar(title = "NDVI", 
                                  barwidth = 1,
                                  barheight = 20,
                                  label.position = "right", 
                                  legend.position = c(0, 0))) +
     theme(legend.position = "right")

## place color bar at bottom
p2 + guides(fill = guide_colorbar(title = "NDVI", 
                                  barwidth = 7,
                                  barheight = .7,
                                  label.position = "bottom", 
                                  legend.position = c(0, 0)),
                                  direction = "horizontal") +
     theme(legend.position = "bottom")
# }

Run the code above in your browser using DataLab