Skip to contents

Generates a `ggplot2` object to visualize CLC Vectorial data. The function processes the data stored in a `clc` object, ensuring that the codes field is mapped correctly to the categories and their associated styles.

Usage

prepare_plot(clo)

# S3 method for class 'clc'
prepare_plot(clo)

Arguments

clo

A `clc` object.

Value

A `ggplot2` object ready for rendering.

See also

plot_clc

Other CLC class functions: as_raster(), clc(), copy_to(), cut_to_extent(), get_colors.clc(), get_levels.clc(), get_raster(), plot_clc(), save_to()

Examples

source_gpkg <- system.file("extdata", "clc.gpkg", package = "clc")
clo <- clc(source = source_gpkg, layer_name = "clc")

p <- clo |>
  prepare_plot()

levels <- clo |>
  get_levels()

p <- p +
  ggplot2::scale_fill_manual(
    values = stats::setNames(levels$color, levels$id),
    labels = stats::setNames(levels$description, levels$id),
    name = ""
  ) +
  ggplot2::theme(
    legend.position = "right",
    legend.key.height = ggplot2::unit(2, "cm"),
    legend.title = ggplot2::element_text(size = 12),
    legend.text = ggplot2::element_text(size = 10)
  ) +
  ggplot2::theme_minimal()

temp_file <- tempfile(fileext = ".png")
png(filename = temp_file, width = 800, height = 600)

p

dev.off()
#> pdf 
#>   2