Skip to content

Commit

Permalink
plainview argument legend now accepts a list describing the colorkey.…
Browse files Browse the repository at this point in the history
… addresses #187
  • Loading branch information
tim-salabim committed Oct 3, 2018
1 parent 098b607 commit 1c51b8e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 31 deletions.
12 changes: 8 additions & 4 deletions R/cubeView.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ cubeView <- function(x,
leg_fl <- paste0(dir, "/legend", ".png")
png(leg_fl, height = 200, width = 80, units = "px",
bg = "transparent", pointsize = 14, antialias = "none")
rasterLegend(col = col.regions,
at = at,
height = 0.9,
space = "right")
rasterLegend(
list(
col = col.regions,
at = at,
height = 0.9,
space = "right"
)
)
dev.off()
}

Expand Down
6 changes: 2 additions & 4 deletions R/legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,6 @@ addRasterLegend <- function(x,


## legend for plainview, slideview, cubeview ==============================
rasterLegend <- function(col, at, ...) {
draw.colorkey(key = list(col = col,
at = at,
...), draw = TRUE)
rasterLegend <- function(key) {
draw.colorkey(key = key, draw = TRUE)
}
22 changes: 16 additions & 6 deletions R/plainView.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ if ( !isGeneric('plainView') ) {
#' @param at the breakpoints used for the visualisation. See
#' \code{\link{levelplot}} for details.
#' @param na.color color for missing values.
#' @param legend logical, whether to draw a legend for the raster layer.
#' @param legend either logical or a list specifying any of the components
#' decribed in the \code{colorkey} section of \link[lattice]{levelplot}.
#' @param verbose should some details be printed during the process
#' @param layer.name the name of the layer to be shown on the map
#' @param gdal logical. If TRUE (default) gdal_translate is used
Expand Down Expand Up @@ -124,21 +125,30 @@ setMethod('plainView', signature(x = 'RasterLayer'),

leg_fl <- NULL

if (legend) {
if (!is_literally_false(legend)) {
if (raster::fromDisk(x) & gdal) {
col.regions = grDevices::grey.colors(256, start = 0, end = 1, gamma = 1)
} else {
col.regions = col.regions
}
rng <- range(x[], na.rm = TRUE)
if (missing(at)) at <- lattice::do.breaks(rng, 256)
leg_fl <- paste0(dir, "/legend", ".png")
png(leg_fl, height = 200, width = 80, units = "px",
bg = "transparent", pointsize = 14, antialias = "none")
rasterLegend(col = col.regions,

if (isTRUE(legend)) {
legend = list(NULL)
}
key = list(col = col.regions,
at = at,
height = 0.9,
space = "right")
# }

key = modifyList(key, legend)

leg_fl <- paste0(dir, "/legend", ".png")
png(leg_fl, height = 200, width = 80, units = "px",
bg = "transparent", pointsize = 14, antialias = "none")
rasterLegend(key)
dev.off()
}

Expand Down
48 changes: 32 additions & 16 deletions R/slideView.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,14 @@ setMethod("slideView", signature(img1 = "RasterLayer",
leg_flr <- paste0(dir, "/legendr", label1, ".png")
png(leg_flr, height = 200, width = 80, units = "px",
bg = "transparent", pointsize = 14)
rasterLegend(col = col.regions,
at = atr,
height = 0.9,
space = "right")
rasterLegend(
list(
col = col.regions,
at = atr,
height = 0.9,
space = "right"
)
)
dev.off()

## legend two (left)
Expand All @@ -203,10 +207,14 @@ setMethod("slideView", signature(img1 = "RasterLayer",
leg_fll <- paste0(dir, "/legendl", label2, ".png")
png(leg_fll, height = 200, width = 80, units = "px",
bg = "transparent", pointsize = 14)
rasterLegend(col = col.regions,
at = atl,
height = 0.9,
space = "left")
rasterLegend(
list(
col = col.regions,
at = atl,
height = 0.9,
space = "left"
)
)
dev.off()
}

Expand Down Expand Up @@ -270,10 +278,14 @@ setMethod("slideView", signature(img1 = "RasterStackBrick",
leg_fll <- paste0(dir, "/legendl", label2, ".png")
png(leg_fll, height = 200, width = 80, units = "px",
bg = "transparent", pointsize = 14)
rasterLegend(col = col.regions,
at = atl,
height = 0.9,
space = "left")
rasterLegend(
list(
col = col.regions,
at = atl,
height = 0.9,
space = "left"
)
)
dev.off()
}

Expand Down Expand Up @@ -340,10 +352,14 @@ setMethod("slideView", signature(img1 = "RasterLayer",
leg_flr <- paste0(dir, "/legendr", label1, ".png")
png(leg_flr, height = 200, width = 80, units = "px",
bg = "transparent", pointsize = 14)
rasterLegend(col = col.regions,
at = atr,
height = 0.9,
space = "right")
rasterLegend(
list(
col = col.regions,
at = atr,
height = 0.9,
space = "right"
)
)
dev.off()
}

Expand Down
3 changes: 2 additions & 1 deletion man/plainView.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1c51b8e

Please sign in to comment.