plotly (version 4.8.0)

raster2uri: Convert a raster object to a data URI

Description

Convenient embedding images via layout() https://plot.ly/r/reference/#layout-images.

Usage

raster2uri(r, ...)

Arguments

r

an object coercable to a raster object via as.raster()

...

arguments passed onto as.raster().

Examples

Run this code
# NOT RUN {
# a red gradient (from ?as.raster)
r <- as.raster(matrix(hcl(0, 80, seq(50, 80, 10)), nrow = 4, ncol = 5))
plot(r)

# embed the raster as an image
plot_ly(x = 1, y = 1) %>% 
  layout(
    images = list(list(
     source = raster2uri(r),
     xref = "paper", 
     yref = "paper", 
     x = 0, y = 0, 
     sizex = 0.5, sizey = 0.5, 
     xanchor = "left", yanchor = "bottom"
  ))
 ) 
# }

Run the code above in your browser using DataCamp Workspace