-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualize_setup.R
More file actions
76 lines (63 loc) · 2.34 KB
/
visualize_setup.R
File metadata and controls
76 lines (63 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
library(ggplot2)
library(dplyr)
# 1. RE-GENERATE THE DESIGN (Simplified for plotting)
set.seed(42)
n_blocks <- 4
pv_types <- c('Control', 'Vertical', 'Overhead')
crops <- c('Wheat', 'Lettuce')
# Storage
plot_data <- data.frame()
for (b in 1:n_blocks) {
# Randomize PV rows within the block
block_pvs <- sample(pv_types)
# Track the physical "Row" number within the block (1, 2, 3)
# This represents the physical strip of land
for (row_idx in 1:length(block_pvs)) {
pv_type <- block_pvs[row_idx]
# Randomize Crops within that PV row
row_crops <- sample(crops)
for (col_idx in 1:length(row_crops)) {
crop_type <- row_crops[col_idx]
plot_data <- rbind(plot_data, data.frame(
Block = factor(paste("Block", b)),
# "Y" coordinate in the field (The PV Row)
FieldRow = factor(row_idx),
# "X" coordinate in the field (The Crop Plot)
FieldCol = factor(col_idx),
PvType = pv_type,
Crop = crop_type,
# The Combined Label for the Heatmap
Treatment = paste(pv_type, "+", crop_type)
))
}
}
}
# 2. CREATE THE HEATMAP ----
# We use geom_tile to draw the plots.
# We use size aesthetic to draw THICK borders around PV rows (Main Plots)
ggplot(plot_data, aes(x = FieldCol, y = FieldRow)) +
# A. The Plots (colored by specific treatment)
geom_tile(aes(fill = Treatment), color = "white", size = 0.5) +
# B. The Main Plot Borders (The Visual "Split-Plot" cue)
# We draw a thick box around the rows to show they are one continuous unit
geom_rect(aes(xmin = 0.5, xmax = 2.5,
ymin = as.numeric(FieldRow) - 0.5,
ymax = as.numeric(FieldRow) + 0.5),
fill = NA, color = "black", size = 1.5) +
# C. Facet by Block to show replications
facet_wrap(~Block, ncol = 2) +
# D. Styling
scale_fill_brewer(palette = "Paired") + # Nice distinct colors
theme_minimal() +
labs(
title = "Agrivoltaic Split-Plot Design Map",
subtitle = "Thick black borders indicate Main Plots (PV Installations).\nColors indicate specific Crop + PV interaction.",
x = "Sub-Plot Position (Crop Location)",
y = "Main-Plot Position (PV Row)",
fill = "Treatment (PV + Crop)"
) +
theme(
panel.grid = element_blank(),
axis.text = element_blank(), # Hide axis numbers for cleaner map look
legend.position = "bottom"
)