packages_needed <- c(“DiagrammeR”, “DiagrammeRsvg”, “rsvg”, “magick”)
for (pkg in packages_needed) { if (!requireNamespace(pkg, quietly = TRUE)) { install.packages(pkg) } }
library(DiagrammeR) library(DiagrammeRsvg) library(rsvg) library(magick)
output_dir <- “D:/Delta State/2025 - Fall/GIS-461/FInal”
if (!dir.exists(output_dir)) { dir.create(output_dir, recursive = TRUE) }
png_path <- file.path(output_dir, “PHX_RoC_flowchart_temp.png”) jpeg_path <- file.path(output_dir, “PHX_RoC_flowchart.jpeg”)
flow <- grViz(” digraph phoenix_flow {
graph [layout = dot, rankdir = TB]
# Default node style node [ fontname = ‘Helvetica’, fontsize = 18 ]
# ————————- # Node definitions # ————————-
# Terminators start [label = ‘Start’, shape = oval, style = filled, fillcolor = ‘#D9EAD3’] end [label = ‘End’, shape = oval, style = filled, fillcolor = ‘#D9EAD3’]
# Setup & environment setwd [label = ‘Set working directory& output paths’, shape = parallelogram, style = filled, fillcolor = ‘#FFF2CC’] libs [label = ‘Load libraries:/ raster / sf / gstat // dplyr / ggplot2’, shape = rectangle, style = filled, fillcolor = ‘#CFE2F3’] objects [label = ’Define objects:= 2002–2022_ids = 1–30= stations 12 & 15’, shape = rectangle, style = filled, fillcolor = ‘#CFE2F3’]
# Decision: files exist? files_ok [label = ‘All station/yearpresent?’, shape = diamond, style = filled, fillcolor = ‘#F4CCCC’]
log_missing [label = ‘Log missing station/year& skip in processing’, shape = rectangle, style = filled, fillcolor = ‘#FCE5CD’]
# Year loop controller year_loop [label = ‘Loop over years:(yr in years)’, shape = rectangle, style = filled, fillcolor = ‘#CFE2F3’]
# Inside year loop read_txt [label = ‘Read AZMET .txt filescurrent year(all stations)’, shape = parallelogram, style = filled, fillcolor = ‘#FFF2CC’]
clean_tbl [label = ‘Clean & filter data:\n• parse dates• keep Tmax (high temp)• remove NAs / bad values’, shape = rectangle, style = filled, fillcolor = ‘#CFE2F3’]
summarise [label = ‘Summarize by station:• daily mean high• annual mean high(emphasize 12 & 15)’, shape = rectangle, style = filled, fillcolor = ‘#CFE2F3’]
join_coords [label = ‘Join with station→ sf points’, shape = rectangle, style = filled, fillcolor = ‘#CFE2F3’]
interp [label = ‘Interpolate Phoenixfor year(IDW / kriging) → raster’, shape = rectangle, style = filled, fillcolor = ‘#CFE2F3’]
save_year [label = ‘Save yearly surface(e.g., PHX_Tmax_yr.tif)& append to raster list’, shape = parallelogram, style = filled, fillcolor = ‘#FFF2CC’]
# After loop stack_ras [label = ‘Create raster stackall yearly surfaces(2002–2022)’, shape = rectangle, style = filled, fillcolor = ‘#CFE2F3’]
trend [label = ‘Per-cell linear model:~ year →of change (°C/yr)’, shape = rectangle, style = filled, fillcolor = ‘#CFE2F3’]
classify [label = ‘Classify RoC raster:• define breaks• choose color ramp(e.g., cooling vs warming)’, shape = rectangle, style = filled, fillcolor = ‘#CFE2F3’]
basemap [label = ‘Optional: add basemap& set RoC layer= 35%’, shape = rectangle, style = filled, fillcolor = ‘#CFE2F3’]
export_map [label = ‘Export finalmap to JPEG(PHX_RoC_map.jpeg)’, shape = parallelogram, style = filled, fillcolor = ‘#FFF2CC’]
# ————————- # Edges (flow) # ————————-
start -> setwd -> libs -> objects -> files_ok
files_ok -> year_loop [label = ‘Yes’, fontsize = 14] files_ok -> log_missing [label = ‘No’, fontsize = 14] log_missing -> year_loop
# Year loop body year_loop -> read_txt -> clean_tbl -> summarise -> join_coords -> interp -> save_year
# Loop back / exit save_year -> year_loop [label = ‘Next year’, fontsize = 14] year_loop -> stack_ras [label = ‘All years’, fontsize = 14]
# Post-processing stack_ras -> trend -> classify -> basemap -> export_map -> end } “)
svg_txt <- export_svg(flow)
rsvg_png( charToRaw(svg_txt), file = png_path, width = 2000, height = 2600 )
img <- image_read(png_path) image_write(img, jpeg_path, format = “jpeg”, quality = 95)
cat(“Flowchart exported to:”, jpeg_path, “”)