analyze_green_and_tree_count_density {greenR}R Documentation

Analyze Green Space or Tree Count Density with Research Metrics and Lorenz Curve

Description

This function analyzes the spatial distribution of green spaces or trees using counts per hexagon, avoiding unreliable area estimates. It calculates inequality and distribution metrics and produces an interactive map, analytics, and optional Lorenz curve and JSON export. Automatically selects binning strategy if data are too sparse for quantile or Jenks categorization.

Usage

analyze_green_and_tree_count_density(
  osm_data,
  mode = c("green_area", "tree_density"),
  h3_res = 8,
  color_palette = c("#FFEDA0", "#74C476", "#005A32"),
  opacity = 0.7,
  tile_provider = c("OpenStreetMap", "Positron", "DarkMatter", "Esri.WorldImagery"),
  enable_hover = TRUE,
  categorization_method = c("quantile", "jenks", "fixed"),
  fixed_breaks = NULL,
  save_html = FALSE,
  html_map_path = "density_map.html",
  save_json = FALSE,
  json_file = "density_data.json",
  save_lorenz = FALSE,
  lorenz_plot_path = "lorenz_curve.png"
)

Arguments

osm_data

Output from get_osm_data(), containing at least osm_data$green_areas$osm_polygons or osm_data$trees$osm_points.

mode

Character. Either "green_area" (green polygon count) or "tree_density" (point count). Default: "green_area".

h3_res

Integer. H3 resolution (0–15). Default = 8.

color_palette

Character vector of 3 colors for choropleth. Default = c("#FFEDA0", "#74C476", "#005A32").

opacity

Numeric. Fill opacity for hexes. Default = 0.7.

tile_provider

Character. One of c("OpenStreetMap", "Positron", "DarkMatter", "Esri.WorldImagery"). Default = "OpenStreetMap".

enable_hover

Logical. Show hover labels. Default = TRUE.

categorization_method

Character. One of c("quantile", "jenks", "fixed"). Default = "quantile".

fixed_breaks

Numeric vector of length 2. Thresholds for "fixed" method. Default = NULL.

save_html

Logical. Save map as self-contained HTML. Default = FALSE.

html_map_path

Character. Filepath for HTML. Default = "density_map.html".

save_json

Logical. Save hex centroid + value JSON. Default = FALSE.

json_file

Character. Filepath for JSON. Default = "density_data.json".

save_lorenz

Logical. Save Lorenz curve PNG. Default = FALSE.

lorenz_plot_path

Character. Filepath for Lorenz PNG. Default = "lorenz_curve.png".

Value

A list with:

map

Leaflet map object

analytics

Named list of summary statistics

json_file

Path to JSON file (if saved)

lorenz_plot

Path to Lorenz PNG (if saved)

Examples

## Not run: 
# Example: green area polygons (default mode)
osm_data <- get_osm_data("Zurich, Switzerland", features = c("green_areas", "trees"))
result <- analyze_green_and_tree_count_density(
  osm_data = osm_data,
  mode = "green_area",
  h3_res = 8,
  save_lorenz = TRUE
)
print(result$analytics)
result$map
result$lorenz_plot

# Example: tree density
result2 <- analyze_green_and_tree_count_density(
  osm_data = osm_data,
  mode = "tree_density",
  h3_res = 8,
  color_palette = c("#F0E442", "#009E73", "#D55E00"),
  save_html = TRUE
)
result2$map

## End(Not run)

[Package greenR version 0.0.1.3 Index]