Learn R Programming

clc (version 1.0.0)

prepare_plot: Prepare a Plot for CLC Vectorial Data

Description

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 clc prepare_plot(clo)

Value

A `ggplot2` object ready for rendering.

Arguments

clo

A `clc` object.

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

Run this code
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()

Run the code above in your browser using DataLab