tests/testthat/test-im.ggplot.R

test_that("multiplication works", {
  expect_equal(2 * 2, 4)
})
library(viridis)
library(testthat)
library(imageRy)
library(terra)
library(ggplot2)



test_that("im.ggplot correctly generates a ggplot object", {
  # Create a raster with two layers (simulating satellite bands)
  r <- rast(nrows = 10, ncols = 10, nlyrs = 2)
  values(r) <- runif(200)  # Assign random values

  # Generate ggplot visualization
  ggplot_raster <- im.ggplot(r, layerfill = 1)

  # Ensure that the result is a ggplot object
  expect_s3_class(ggplot_raster, "ggplot")

  # Check that the plot contains a raster (geom_raster)
  plot_layers <- lapply(ggplot_raster$layers, function(layer) class(layer$geom)[1])
  expect_true("GeomRaster" %in% plot_layers)
})

Try the imageRy package in your browser

Any scripts or data that you put into this service are public.

imageRy documentation built on Aug. 8, 2025, 7:31 p.m.