-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapping-kelp-results.Rmd
644 lines (530 loc) · 20.5 KB
/
mapping-kelp-results.Rmd
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
---
title: "Mapping Locations for Kelp Aquaculture in R"
author: "Elke Windschitll"
date: "2023-11-02"
output: html_document
---
Description: In this qmd, I create a publishable map of locations that have habitat that is likely suitable for kelp aquaculture near Santa Barbara.
## Introduction
While earning my master's of environmental data science from the University of California, Santa Barbara, I completed a group capstone project with three other peers. Our clients included Natalie Dornan, a researcher at UCSB, and Ocean Rainforest, an aquaculture company with operations in Santa Barbara. We were tasked with combining open source data sets on giant kelp and various oceanographic factors in the region to create one synthesized data product. We were asked to use that data product to model habitat suitability for giant kelp to aid Ocean Rainforest in siting aquaculture projects in the future. Here, I map the final results of those efforts.
## The Data
I used five types of data in this process. I used the model results from our species distribution habitat suitability modeling, substrate data, and boundary data of state boundaries, federal boundaries, and marine protected areas. Metadata on these data sources can be found in the [kelpGeoMod data repository](https://drive.google.com/drive/u/2/folders/1sJq_9RnsARR9mkmrcrn4O_1630VD-e-t).
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
# Load libraries
library(sf)
library(terra)
library(tmap)
library(readr)
library(raster)
library(dplyr)
library(maptiles)
library(cowplot)
library(ggspatial)
library(tidyterra)
library(ggplot2)
#---- Set up the data directory
#data_dir <- insert your file path to your data
```
```{r include=FALSE}
data_dir <- "/Users/elkewindschitl/Documents/MEDS/kelpGeoMod/final-data"
```
```{r}
# Read in data
# Read in project AOI
aoi <- st_read(file.path(data_dir, "02-intermediate-data/02-aoi-sbchannel-shapes-intermediate/aoi-sbchannel.shp"))
# Read in the counties data
counties <- st_read(file.path(data_dir, "01-raw-data/02-ca-county-land-boundaries-raw/California_County_Boundaries/cnty19_1.shp"))
# Convert counties data to WGS84
counties <- st_transform(counties, "+proj=longlat +datum=WGS84")
# Read in federal boundaries
fed_bounds <- st_read(file.path(data_dir, "01-raw-data/federal_boundaries/USMaritimeLimitsNBoundaries.shp")) %>%
filter(REGION == "Pacific Coast")
# Read in the 3-nautical mile state boundary
state_bounds <- st_read(file.path(data_dir, "01-raw-data/state_boundaries/stanford-sg211gq3741-shapefile/sg211gq3741.shp"))
# Read in MPAs
mpas <- st_read(file.path(data_dir, "01-raw-data/04-mpa-boundaries-raw/California_Marine_Protected_Areas_[ds582]/California_Marine_Protected_Areas_[ds582].shp"))
# Read in sandy-bottom raster
sandy_raster <- raster(file.path(data_dir, "03-analysis-data/05-substrate-analysis/sandy-bottom-1km.tif"))
# Read in rocky-bottom raster
#rocky_raster <- raster(file.path(data_dir, "03-analysis-data/05-substrate-analysis/rocky-bottom-1km.tif"))
# Read in kelp brick
kelp <- brick(file.path(data_dir, "02-intermediate-data/05-kelp-area-biomass-intermediate/kelp-area-brick.tif"))
```
```{r}
# (Code from Erika)
# Create function to average kelp area per grid cell over all years by quarter
calc_seasonal_means_brick <- function(rast_to_convert) {
quarter_sets <- list(seq(from = 1, to = 36, by = 4), # Q1s (winter)
seq(from = 2, to = 36, by = 4), # Q2s (spring)
seq(from = 3, to = 36, by = 4), # Q3s (summer)
seq(from = 4, to = 36, by = 4)) # Q4s (fall)
all_seasons_brick <- brick() # set up brick to hold averaged layers for each season (will have 4 layers at the end)
for (i in seq_along(quarter_sets)) {
season_brick_holder <- brick() # hold all layers for one season, then reset for next season
for (j in quarter_sets[[i]]) {
season_brick <- brick() # hold single layer in a season, then reset for next layer
season_brick <- addLayer(season_brick, rast_to_convert[[j]]) # add single layer to initialized brick
season_brick_holder <- addLayer(season_brick_holder, season_brick) # add this layer to the holder for this season, and repeat until have all layers from season
}
season_averaged_layer <- calc(season_brick_holder, mean) # after having all layers from season, take the mean
all_seasons_brick <- addLayer(all_seasons_brick, season_averaged_layer) # add mean to the brick holding all averaged layers, and then repeat for the next season
}
return(all_seasons_brick) # return the resulting brick object
}
kelp_all <- calc_seasonal_means_brick(rast_to_convert = kelp)
kelp_quarter1 <- kelp_all[[1]]
kelp_quarter2 <- kelp_all[[2]]
kelp_quarter3 <- kelp_all[[3]]
kelp_quarter4 <- kelp_all[[4]]
```
```{r}
# Maxent Outputs
# Prep for plotting
# ---------------------------------Quarter 1 ---------------------------------
# Read in kelp data and make sf object
# kelp_1 <- read_csv(file.path(data_dir, "03-analysis-data/04-maxent-analysis/quarter-1/kelp-presence-1.csv")) %>%
# st_as_sf(coords = c("longitude", "latitude"), crs = 4326)
# Read in the maxent output
maxent_quarter_1 <- raster(file.path(data_dir, "03-analysis-data/04-maxent-analysis/results/maxent-quarter-1-output.tif"))
# ---------------------------------Quarter 2 ---------------------------------
# kelp_2 <- read_csv(file.path(data_dir, "03-analysis-data/04-maxent-analysis/quarter-2/kelp-presence-2.csv")) %>%
# st_as_sf(coords = c("longitude", "latitude"), crs = 4326)
# Read in the maxent output
maxent_quarter_2 <- raster(file.path(data_dir, "03-analysis-data/04-maxent-analysis/results/maxent-quarter-2-output.tif"))
# ---------------------------------Quarter 3 ---------------------------------
# kelp_3 <- read_csv(file.path(data_dir, "03-analysis-data/04-maxent-analysis/quarter-3/kelp-presence-3.csv")) %>%
# st_as_sf(coords = c("longitude", "latitude"), crs = 4326)
# Read in the maxent output
maxent_quarter_3 <- raster(file.path(data_dir, "03-analysis-data/04-maxent-analysis/results/maxent-quarter-3-output.tif"))
# ---------------------------------Quarter 4 ---------------------------------
# read_csv(file.path(data_dir, "03-analysis-data/04-maxent-analysis/quarter-4/kelp-presence-4.csv")) %>%
# st_as_sf(coords = c("longitude", "latitude"), crs = 4326)
# Read in the maxent output
maxent_quarter_4 <- raster(file.path(data_dir, "03-analysis-data/04-maxent-analysis/results/maxent-quarter-4-output.tif"))
```
### Masked output
```{r}
# Prep data
# Reclassify values <0.4 to NA for each quarter and mask out areas with kelp
rcl_1 <- maxent_quarter_1 %>%
reclassify(cbind(0, 0.4, NA), right=FALSE) %>%
mask(mask = kelp_quarter1, inverse = TRUE)
rcl_2 <- maxent_quarter_2 %>%
reclassify(cbind(0, 0.4, NA), right=FALSE) %>%
mask(mask = kelp_quarter2, inverse = TRUE)
rcl_3 <- maxent_quarter_3 %>%
reclassify(cbind(0, 0.4, NA), right=FALSE) %>%
mask(mask = kelp_quarter3, inverse = TRUE)
rcl_4 <- maxent_quarter_4 %>%
reclassify(cbind(0, 0.4, NA), right=FALSE) %>%
mask(mask = kelp_quarter4, inverse = TRUE)
good_cells_stack <- stack(rcl_1, rcl_2, rcl_3, rcl_4) #stack
# Mask to areas that meet a minimum of 0.4 for all quarters
# Create an empty raster with the same extent and resolution as the input rasters
maxent_mask <- raster(good_cells_stack[[1]])
values(maxent_mask) <- 1 # Set all cells in the mask raster to a common value
# Iterate over each raster and update the mask raster where they overlap
for (i in 1:4) {
maxent_mask <- maxent_mask * (good_cells_stack[[i]]) # Update the mask where raster values are zero
}
# Mask rcl_1
masked_rcl_1 <- mask(rcl_1, maxent_mask)
# Mask rcl_2
masked_rcl_2 <- mask(rcl_2, maxent_mask)
# Mask rcl_3
masked_rcl_3 <- mask(rcl_3, maxent_mask)
# Mask rcl_4
masked_rcl_4 <- mask(rcl_4, maxent_mask)
# Take the mean value of all four quarters
mean_masked_maxent <- mean(masked_rcl_1, masked_rcl_2, masked_rcl_3, masked_rcl_4)
#range_masked_maxent <- range(masked_rcl_1, masked_rcl_2, masked_rcl_3, masked_rcl_4)
#max_masked_maxent <- max(masked_rcl_1, masked_rcl_2, masked_rcl_3, masked_rcl_4)
# Mask to areas with sandy-bottom substrate
#sub_masked_model <- mask(x = mean_masked_maxent, mask = sandy_raster, inverse = FALSE)
```
```{r}
# small <- res(rocky_raster)[1] # grab our smallest resolution
# large <- res(mean_masked_maxent)[2] # grab our largest resoultion
#
# # Calculate the resample factor
# factor <- c(large / small, large / small) # Divide the target resolution (3 km) by the source resolution (1 km)
#
# # Convert to package terra
#rocky_terra <- rast(rocky_raster)
sandy_terra <- rast(sandy_raster)
maxent_terra <- rast(mean_masked_maxent)
#range_maxent_terra <- rast(range_masked_maxent)
#max_maxent_terra <- rast(max_masked_maxent)
#
# # Disaggregate to match susbtrate resolution
# disagg_max <- terra::disagg(x = maxent_terra,
# fact = factor, # number of cells in each direction
# method = "near")
#
# # resample to match mask exactly
# resampled <- terra::resample(disagg_max, rocky_terra, method = "near")
# Mask maxent to areas with sandy-bottom
sub_masked_model <- terra::mask(x = maxent_terra, mask = sandy_terra, inverse = FALSE)
#range_masked_model <- terra::mask(x = range_maxent_terra, mask = sandy_terra, inverse = FALSE)
#max_masked_model <- terra::mask(x = max_maxent_terra, mask = sandy_terra, inverse = FALSE)
```
```{r}
# sub_masked_model_downsampled <- aggregate(sub_masked_model, fact = 100) # Adjust the factor as needed
#
# masked_tm <- tm_shape(sub_masked_model_downsampled , raster.warp = FALSE) +
# tm_raster() +
#
# tm_shape(counties) +
# tm_polygons() +
#
# tm_shape(aoi, bbox = bbox) +
# tm_borders(lwd = 2, col = dark_blue)
#
# masked_tm
```
This map shows the mean predicted habitat suitability for grid cells that:
1. Have a minimum of 0.4 habitat suitability in ALL quarters
2. Did not have any kelp seen in them (as of 2014-2022 from remotely sensed data)
3. Have a majority rocky or mixed substrate
```{r}
# Transform to get every layer in same crs
aoi <- st_transform(aoi, crs = 4326)
mpas <- st_transform(mpas, crs = 4326)
fed_bounds <- st_transform(fed_bounds, crs = 4326)
state_bounds <- st_transform(state_bounds, crs = 4326)
# Define the amount of aoi buffer I want
buffer_size <- 10000
# Create a buffer around the AOI
buffered_aoi <- st_buffer(aoi, buffer_size)
# Reduce shape file data sets to only in my area of interest + buffer
aoi_mpas <- st_intersection(mpas, buffered_aoi)
aoi_fed_bounds <- st_intersection(fed_bounds, buffered_aoi)
aoi_state_bounds <- st_intersection(state_bounds, buffered_aoi)
```
```{r}
# Remove na values from raster
no_na <- mask(sub_masked_model, !is.na(sub_masked_model))
# Mask out locations within mpas
no_na_no_mpa <- mask(no_na, aoi_mpas, inverse = TRUE)
# Convert to point data
target_points <- as.data.frame(no_na_no_mpa, xy = TRUE, na.rm = TRUE) %>%
st_as_sf(coords = c("x", "y"),
crs = st_crs(4326))
# tm_shape(target_points) +
# tm_dots()
#
# tm_shape(no_na) +
# tm_raster()
```
```{r}
# tmap_mode("plot")
# tm_shape(basemap) +
# tm_rgb() +
# tm_shape(aoi_fed_bounds) +
# tm_lines() +
#
# tm_shape(aoi_state_bounds) +
# tm_polygons(col = "orange3") +
#
# tm_shape(aoi_mpas) +
# tm_polygons(col = "red4") +
#
# tm_shape(maxent_quarter_1) +
# tm_raster()
```
```{r}
# define the tile server parameters
# osmpos <- create_provider(
# name = "CARTO.POSITRON",
# url = "https://cartodb-basemaps-{subDomain}.global.ssl.fastly.net/light_only_labels/{level}/{col}/{row}.png",
# sub = c("a", "b", "c", "d"),
# citation = "© OpenStreetMap contributors © CARTO "
# )
# dowload tiles and compose raster (SpatRaster)
basemap <- get_tiles(
x = buffered_aoi, provider = "CartoDB.DarkMatterNoLabels", crop = TRUE,
cachedir = tempdir(), verbose = TRUE
)
# display map
# plot_tiles(basemap)
#
# plot(st_geometry(aoi_state_bounds), col = NA, add = TRUE)
#
# plot(st_geometry(aoi), col = NA, add = TRUE)
#
# plot(st_geometry(aoi_fed_bounds), col = NA, add = TRUE)
# display credits
# mtext(
# text = get_credit(osmpos),
# side = 1, line = -1, adj = 1,
# cex = .9, font = 3
# )
```
```{r}
small_box <- tribble(
~lat, ~lon,
34.35, -119.54412,
34.5, -120.30751,
34.35, -120.30751,
34.5, -119.54412
) |>
st_as_sf(coords = c("lon", "lat"),
crs = "EPSG: 4326") |>
st_bbox() |>
st_as_sfc()
```
```{r}
# tmap_mode("view")
# tmap_mode("plot")
# big_plot <-tm_shape(basemap) +
# tm_rgb() +
#
# tm_shape(aoi_fed_bounds) +
# tm_lines(lty = 6) +
#
# tm_shape(aoi_state_bounds) +
# tm_borders(col = "black", lty = 1) +
#
# tm_shape(aoi_mpas) +
# tm_borders(col = "gray", alpha = 0.1) +
# tm_fill(col = "gray", alpha = 0.05) +
#
# tm_shape(aoi) +
# tm_borders(col = "#203e63", lwd = 2) +
#
# tm_shape(target_points) +
# tm_dots(col = "#849638", size = 0.05) +
#
# tm_shape(small_box) +
# tm_borders(col = "#de8728", lwd = 0.2)
```
```{r}
# Plot the full AOI
big_plot <- ggplot() +
geom_spatraster_rgb(
mapping = aes(),
basemap,
interpolate = TRUE,
r = 1,
g = 2,
b = 3
) +
geom_sf(data = aoi_fed_bounds,
linetype = "dotdash") +
geom_sf(data = aoi_state_bounds,
col = "black",
alpha = 0,
linetype = "solid",
linewidth = 0.3) +
geom_sf(data = aoi_mpas,
fill = "#a6a6a6",
colour = "#a6a6a6",
alpha = 0.1) +
geom_sf(data = aoi,
color = "#203e63",
alpha = 0,
linewidth = 0.8) +
geom_sf(data = target_points,
color = "#849638",
size = 0.05) +
geom_sf(data = small_box,
colour = "#de8728",
alpha = 0,
linewidth = 0.1) +
theme(panel.background = element_blank(),
plot.background = element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank(),
panel.grid = element_blank()) +
annotation_scale(pad_x = unit(1.1, "in"),
pad_y = unit(0.55, "in"),
bar_cols = c("black", "#262626"),
height = unit(0.25, "cm"),
text_col = "#a6a6a6") +
annotation_north_arrow(pad_x = unit(0.6, "in"),
pad_y = unit(0.45, "in"),
height = unit(0.25, "in"),
width = unit(0.3, "in"),
style = north_arrow_orienteering(fill = c("black", "#262626"),
text_col = "#a6a6a6"))
big_plot
```
```{r}
# Create a custom legend plot
legend_plot <- ggplot() +
geom_segment(aes(x = 0, xend = 1, y = 0, yend = 0, linetype = "1"), color = "black", linewidth = 2) +
geom_segment(aes(x = 0, xend = 1, y = -1, yend = -1, linetype = "2"), color = "black", linewidth = 2) +
geom_segment(aes(x = 0, xend = 1, y = -2, yend = -2, linetype = "3"), color = "#a6a6a6", linewidth = 2) +
geom_segment(aes(x = 0, xend = 1, y = -3, yend = -3, linetype = "4"), color = "#203e63", linewidth = 2) +
scale_linetype_manual(values = c("solid", "dotdash", "solid", "solid")) +
theme(panel.background = element_blank(),
plot.background = element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank(),
axis.title = element_blank(),
panel.grid = element_blank(),
panel.margin = margin(c(0,0,500,0)),
plot.margin = margin(c(0,0,10,0))) +
coord_cartesian(clip = "off") +
theme(legend.position = "none") +
annotate("text",
x = .33,
y = -.3,
label = "State Boundary",
color = "black",
size = 12)+
annotate("text",
x = .38,
y = -1.3,
label = "Federal Boundary",
color = "black",
size = 12)+
annotate("text",
x = .47,
y = -2.3,
label = "Marine Protected Area",
color = "#a6a6a6",
size = 12) +
annotate("text",
x = .39,
y = -3.3,
label = "Project Study Area",
color = "#203e63",
size = 12)
legend_plot
# Save the legend using this trick:
# In RStudio, click on "Zoom", and then zoom the plot to the size and aspect ratio that satisfy you;
# Right click on the plot, then "Copy Image Address", paste the address somewhere, you get the width (www) and height (hhh) information in the address;
# ggsave("plot.png", width = www/90, height = hhh/90, dpi = 900) ggsave("plot.pdf", width = www/90, height = hhh/90)
#https://stackoverflow.com/questions/75020376/save-plot-exactly-as-previewed-in-the-plots-panel
# http://127.0.0.1:35585/graphics/plot_zoom_png?width=520&height=400
ggsave("images/kelp_legend.png", plot = legend_plot, width = 502/90, height = 400/90, units = "in", dpi = 900)
# Adjust the legend plot size and appearance
# legend_big_plot <- big_plot + draw_plot(legend_plot, .5, .5, .5, .5)
# legend_big_plot
#
# ggdraw(big_plot) + draw_plot(legend_plot, .92, .1, 1, .4)
```
```{r}
# Crop mpas and state bounds to the inset map
aoi_mpas2 <- st_crop(mpas, small_box)
aoi_state_bounds2 <- st_crop(state_bounds, small_box)
# Dowload tiles and compose raster (SpatRaster)
basemap2 <- get_tiles(
x = small_box, provider = "CartoDB.DarkMatterNoLabels", crop = TRUE,
cachedir = tempdir(), verbose = TRUE
)
# small_plot <- tm_shape(basemap2) +
# tm_rgb() +
#
# tm_shape(aoi_state_bounds2) +
# tm_borders(col = "black", lty = 1) +
#
# tm_shape(aoi_mpas2) +
# tm_borders(col = "gray", alpha = 0.1) +
# tm_fill(col = "gray", alpha = 0.05) +
#
# tm_shape(target_points) +
# tm_dots(col = "#849638", size = 0.2) +
#
# tm_shape(small_box) +
# tm_borders(col = "#de8728", lwd = 2)
```
```{r}
# Plot the inset map
small_plot <- ggplot() +
geom_spatraster_rgb(
mapping = aes(),
basemap2,
interpolate = TRUE,
r = 1,
g = 2,
b = 3
) +
geom_sf(data = aoi_state_bounds2,
col = "black",
alpha = 0,
linetype = "solid",
linewidth = 0.3) +
geom_sf(data = aoi_mpas2,
fill = "#a6a6a6",
colour = "#a6a6a6",
alpha = 0.1) +
geom_sf(data = target_points,
color = "#849638",
size = 2) +
geom_sf(data = small_box,
colour = "#de8728",
alpha = 0,
linewidth = 1) +
annotate("text",
x = -119.6982,
y = 34.43,
label = "Santa Barbara",
color = "#a6a6a6") +
annotate("text",
x = -119.86,
y = 34.43,
label = "Goleta",
color = "#a6a6a6") +
annotate("text",
x = -120.2149,
y = 34.478,
label = "Gaviota",
color = "#a6a6a6") +
theme(panel.background = element_blank(),
plot.background = element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank(),
axis.title = element_blank(),
panel.grid = element_blank()) +
annotation_scale(pad_x = unit(0.7, "in"),
pad_y = unit(0.2, "in"),
bar_cols = c("black", "#262626"),
height = unit(0.25, "cm"),
text_col = "#a6a6a6")
small_plot
```
```{r}
# Define the plot background color
bg_color <- "#262626"
# Grab legend from big plot
# legend <- get_legend(big_plot)
# Arrange the plots using plot_grid
combined_plot <- plot_grid(small_plot, big_plot, ncol = 1, axis = "l", rel_heights = c(1, 2.2))
# Set the background color for the entire combined plot + add lines
combined_plot <- combined_plot +
theme(plot.background = element_blank(),
axis.ticks = element_blank()) +
draw_line(
x = c(0.316, 0.167),
y = c(0.523, 0.715),
color = "#de8728", size = 0.2
) +
draw_line(
x = c(0.56, 0.836),
y = c(0.523, 0.715),
color = "#de8728", size = 0.2
)
# Display the combined plot
print(combined_plot)
# Save the plot
#http://127.0.0.1:35585/graphics/plot_zoom_png?width=1309&height=796
ggsave("images/kelp_plot.png", plot = combined_plot, width = 1309/90, height = 796/90, units = "in", dpi = 900)
```
```{r}
# # Combine the legend with your combined plot
# combined_plot_with_legend <- plot_grid(combined_plot, legend_plot, ncol = 2, axis = "b", rel_widths = c(1, 0.5), rel_heights = c(1, 0.5))
#
#
# # Set the background color for the entire combined plot
# combined_plot_with_legend <- combined_plot_with_legend +
# theme(plot.background = element_rect(color = "#262626", fill = "#262626"),
# axis.ticks = element_blank())
#
# # Display the combined plot with the legend
# print(combined_plot_with_legend)
```