Skip to content

Commit 6207d2f

Browse files
authored
Add support for native rasters to annotation_raster() #3388 (#3794)
Closes #3388.
1 parent 0cbb078 commit 6207d2f

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# ggplot2 (development version)
22

3+
* `annotation_raster()` adds support for native rasters. For large rasters,
4+
native rasters render significantly faster than arrays (@kent37, #3388)
5+
36
# ggplot2 3.3.0
47

58
* Fix a bug in `geom_raster()` that squeezed the image when it went outside

R/annotation-raster.r

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ NULL
1010
#' of the raster, and the raster must already have its own colours). This
1111
#' is useful for adding bitmap images.
1212
#'
13-
#' @param raster raster object to display
13+
#' @param raster raster object to display, may be an `array` or a `nativeRaster`
1414
#' @param xmin,xmax x location (in data coordinates) giving horizontal
1515
#' location of raster
1616
#' @param ymin,ymax y location (in data coordinates) giving vertical
@@ -39,7 +39,8 @@ NULL
3939
#' geom_point()
4040
annotation_raster <- function(raster, xmin, xmax, ymin, ymax,
4141
interpolate = FALSE) {
42-
raster <- grDevices::as.raster(raster)
42+
if (!inherits(raster, 'nativeRaster'))
43+
raster <- grDevices::as.raster(raster)
4344

4445
layer(
4546
data = dummy_data(),

man/annotation_raster.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)