-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis_NORC.Rmd
4108 lines (3267 loc) · 210 KB
/
analysis_NORC.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
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "FRIS/IWMS Analysis: No maps or trends plots"
author: "Britta Schumacher"
date: "12/16/2020"
output:
html_document:
theme: flatly
toc: yes
toc_float: true
code_folding: hide
---
# Prepare data for analyses
#### Pull in data from step 11, build-panels-for-analysis.Rmd. First, we'll work with the full-panel-FRIS.RDS to draw summary statistics for each year-by-county and for all years-by-county.
Bring in packages & data built in step 11, build-panels-for-analysis.Rmd
```{r message = F, warning = F}
library(tidyverse)
library(dplyr)
library(ggplot2)
library(corrplot)
library(sp)
library(spdplyr)
library(tmap)
library(rgdal)
library(RColorBrewer)
library(gridExtra)
library(ggplot2)
library(ggpubr)
library(rgeos)
options(scipen=999) # no scientific notation
fris <- readRDS("./data/full-panel-FRIS.RDS")
```
# Build county-level summary statistics
### Find estimated average yield
Code Chunk A):
**DATA IN**: full-panel-FRIS.RDS
Find estimated average yield, water applied, and irrigation productivity across years.
As a reminder, the following data comes from *key variables*: K50, K51, K52, K53 (CORN GRAIN); K60, K61, K62, K63 (CORN SILAGE); K80, K81, K82, K83 (WHEAT); K142, K143 (ALFALFA); K150, K151, K152, K153 (OTHER HAY). These variables represent:
K50: acres harvested (I converted all acres to hectares)
K51: yield (I converted all yield to pounds, and then kilograms and Megagrams in irrigation-productivity.RDS)
K52: water use (I took all water use in acre feet/acre and converted in to inches/acre, cubic cm/hectare, and cubic meters/hectare, again, in irrigation-productivity.RDS).
#### Now, we will take 'statewij' and use it to build all county-level summary statistics as follows (thanks to Matt Fetter at NASS for these exact instructions):
1) Create df with statewij, K51 (acres harvested), K61 (reported yield/acre) [I am adding GEOID, YEAR, etc.]; I converted all reported yields to lbs/acre and kg/acre & lbs/hectare and kg/hectare;
2) create new column: multiply K50*K51 (harvested lbs OR kg);
3) create new column: expanded acres harvested (statewij*K50);
4) create new column: expanded harvested (step 2 *statewij);
5) create summary table: summarise at the county level by sum(expanded harvested) / sum(expanded acres harvested) to get a county-level yield/acre.
```{r A) WEIGHTED YIELD, warning = FALSE, message = FALSE}
### following the instructions given to me on 10/7 by Matt Fetter at NASS
# 1) Create df with statewij, K51 (acres harvested), K61 (reported yield/acre) [I am adding GEOID, YEAR, etc.]; I converted all reported yields to lbs/acre, kg/hectare, and Mg/hectare, and all water use from AF/acre to in/acre, and cm/hectare, m/hectare
weighted <- fris %>%
select(GEOID, STPOID, YEAR, STATE_ALPHA, STATE_ABBR, STATEFP, COUNTY_ALPHA, COUNTYFP, statewij, CROP, ACRES_HARV, HECTARES_HARV, YIELD_LBS, YIELD_KG, YIELD_Mg, WATER_AF, WATER_IN, WATER_CM, WATER_M)
# 2) create new column(s): multiply K50*K51 (harvested lbs OR kg)
weighted <- weighted %>%
mutate(HARVESTED_LBS = ACRES_HARV*YIELD_LBS,
HARVESTED_KG = HECTARES_HARV*YIELD_KG,
HARVESTED_Mg = HECTARES_HARV*YIELD_Mg)
# 3) create new column: expanded acres harvested (statewij*K50)
weighted <- weighted %>%
mutate(w_ACRES_HARV = ACRES_HARV*statewij,
w_HECTARES_HARV = (HECTARES_HARV*statewij))
# 4) create new column: expanded harvested (step 2 *statewij)
weighted <- weighted %>%
mutate(w_HARVESTED_LBS = HARVESTED_LBS*statewij,
w_HARVESTED_KG = HARVESTED_KG*statewij,
w_HARVESTED_Mg = HARVESTED_Mg*statewij)
# 5) create summary table: summarise at the county level by sum(expanded harvested) / sum(expanded acres harvested) to get a county-level yield/acre
yield <- weighted %>%
group_by(GEOID, CROP, YEAR) %>%
summarise(sum_w_ACRES_HARV = sum(w_ACRES_HARV),
sum_w_HECTARES_HARV = sum(w_HECTARES_HARV),
sum_w_HARVESTED_LBS = sum(w_HARVESTED_LBS),
sum_w_HARVESTED_KG = sum(w_HARVESTED_KG),
sum_w_HARVESTED_Mg = sum(w_HARVESTED_Mg),
EST_AVE_YIELD_LBS = sum_w_HARVESTED_LBS/sum_w_ACRES_HARV,
EST_AVE_YIELD_KG = sum_w_HARVESTED_KG/sum_w_HECTARES_HARV,
EST_AVE_YIELD_Mg = sum_w_HARVESTED_Mg/sum_w_HECTARES_HARV)
# Just as a check on things, let's see how different these weighted stats are from the raw
yield_unweight <- weighted %>%
group_by(GEOID, CROP, YEAR) %>%
summarise(mean_YIELD_LBS = mean(YIELD_LBS),
mean_YIELD_KG = mean(YIELD_KG),
mean_YIELD_Mg = mean(YIELD_Mg))
# most estimates are very, very different but even the highest estimated alfalfa yield is within reasonable range for the irrigated west (~ 10 tons/acre)
# select just estimated average columns and SAVE
yield_sub <- yield %>%
select(GEOID, CROP, YEAR, EST_AVE_YIELD_LBS, EST_AVE_YIELD_KG, EST_AVE_YIELD_Mg)
```
### Find estimated average water applied
Code chunk B):
**DATA IN**: full-panel-FRIS.RDS
We are going to follow thise same instructions as listed above (Steps 2-6) to build weighted - water applied.
Additionally, we include step 7:
7) Merge average estimated yield (yield) and average estimated water use (water) into yield_water dataframe(). These dataframes consist only of average estimated yields and water uses across different metric (e.g., cubic meters/hectare, kg/hectare) and US (e.g., acre feet/acre, lbs/acre) measurements. They include no raw data.
```{r B) WEIGHTED WATER APPLIED, warning = FALSE, message = FALSE}
### following the instructions given to me on 10/7 by Matt Fetter at NASS
# 1) Create df with statewij, K51 (acres harvested), K61 (reported yield/acre) [I am adding GEOID, YEAR, etc.]; I converted all reported yields to lbs/acre, kg/hectare, and Mg/hectare, and all water use from AF/acre to in/acre, and cm/hectare, m/hectare
## We will use the dataframe created, above in step 2), below:
# 2) create new column(s): multiply K50*K52 (water used AF-IN-CM-M)
weighted <- weighted %>%
mutate(WU_AF = ACRES_HARV*WATER_AF,
WU_IN = ACRES_HARV*WATER_IN,
WU_CM = HECTARES_HARV*WATER_CM,
WU_M = HECTARES_HARV*WATER_M)
# 3) create new column: expanded acres harvested (statewij*K50)
## Column already created in 'weighted' df --> w_HECTARES_HARV, w_ACRES_HARV
# 4) create new column: expanded water used (step 2 *statewij)
weighted <- weighted %>%
mutate(w_WU_AF = WU_AF*statewij,
w_WU_IN = WU_IN*statewij,
w_WU_CM = WU_CM*statewij,
w_WU_M = WU_M*statewij)
# create summary table: summarise at the county level by sum(expanded harvested) / sum(expanded acres harvested) to get a county-level yield/acre
water <- weighted %>%
group_by(GEOID, CROP, YEAR) %>%
summarise(sum_w_ACRES_HARV = sum(w_ACRES_HARV),
sum_w_HECTARES_HARV = sum(w_HECTARES_HARV),
sum_w_WU_AF = sum(w_WU_AF),
sum_w_WU_IN = sum(w_WU_IN),
sum_w_WU_CM = sum(w_WU_CM),
sum_w_WU_M = sum(w_WU_M),
EST_AVE_WU_AF = sum_w_WU_AF/sum_w_ACRES_HARV,
EST_AVE_WU_IN = sum_w_WU_IN/sum_w_ACRES_HARV,
EST_AVE_WU_CM = sum_w_WU_CM/sum_w_HECTARES_HARV,
EST_AVE_WU_M = sum_w_WU_M/sum_w_HECTARES_HARV)
# Just as a check on things, let's see how different these weighted stats are from the raw
water_unweight <- weighted %>%
group_by(GEOID, CROP, YEAR) %>%
summarise(mean_WU_AF = mean(WATER_AF),
mean_WU_IN = mean(WATER_IN),
mean_WU_CM = mean(WATER_CM),
mean_WU_M = mean(WATER_M))
# most estimates are PRETTY close in AF so these estimates feel reasonable
# select just estimated average columns and SAVE
water_sub <- water %>%
select(GEOID, CROP, YEAR, EST_AVE_WU_AF, EST_AVE_WU_IN, EST_AVE_WU_CM, EST_AVE_WU_M)
# Merge yield-water use, then save!
yield_water <- merge(yield_sub, water_sub, by = c("GEOID", "CROP", "YEAR"))
```
### Find estimated average irrigation productivity
Code chunk C):
**DATA IN**: full-panel-FRIS.RDS
**DATA OUT**: sumstat_indyrs.csv & sumstat_allyrs.csv
We will measure irrigation productivity as: weight harvested/unit water applied.
We'll call this step 8 and 9 of the data building process:
8) Build a function to calculate the estimated average yield per unit water applied. Here, we'll take the average estimated yield we built in code chunk A) divided by the average estimated water applied we built in code chunk B) to get an estimated average irrigation productivity. First we will complete this task for individual years (ie. county-year-crop combinations) and save these summary statistics .RDSs out to DEER as 'sumstat_indyrs.RDS'.; then,
9) We will build a function to create the same metrics, but we will summarise across all years. Thus, our function will be modified--we will still mask for all county-crop combinations with fewer than *n* >= 6 observations, but we will be summarising across *ALL* years. We will save these summary statistics .RDSs out to DEER as 'sumstat_allyrs.RDS'.
Again, these dataframes/.RDSs consist only of average estimated yields, water uses, and irrigation productivities across different metric (e.g., cubic meters/hectare, kg/hectare, kg/cubic meter) and US (e.g., acre feet/acre, lbs/acre, lbs/acre foot) measurements. They include no raw data.
```{r C) ESTIMATED AVERAGE IRRIGATION PRODUCTIVITY, warning = FALSE, message = FALSE}
# Use yield and water use at n >= 6/cty-yr, and find estimated average irrigation productivity for each crop-cty-yr combination
ss <- function(df) {
use <- weighted %>%
group_by(GEOID, CROP, YEAR) %>%
summarise(unique = length(unique((STPOID))),
max_wateruse_AF = max(WATER_AF),
max_yield_lbs = max(YIELD_LBS),
max_acres = max(ACRES_HARV),
total_weighted_acres = sum(w_ACRES_HARV)) %>%
filter(unique >= 6)
use_me <- merge(use, df, by = c("GEOID", "CROP", "YEAR"))
summary_ip <- use_me %>%
group_by(GEOID, CROP, YEAR) %>%
mutate(EST_IP_LBS_AF = EST_AVE_YIELD_LBS/EST_AVE_WU_AF, # estimated average pounds/acre foot
EST_IP_LBS_IN = EST_AVE_YIELD_LBS/EST_AVE_WU_IN, # estimated average pounds/cubic inch
EST_IP_KG_CM = EST_AVE_YIELD_KG/EST_AVE_WU_CM, # estimated average kg/cubic cm
EST_IP_KG_M = EST_AVE_YIELD_KG/EST_AVE_WU_M) %>% # estimated average kg/cubic m
select(-c(EST_AVE_YIELD_Mg))
}
ip_indyrs <- ss(yield_water)
#saveRDS(ip_indyrs, "./out/DEER/sumstat_indyrs.RDS")
write.csv(ip_indyrs, "./out/DEER/sumstat_indyrs.csv")
# Modify the function above to summarise the 'weighted' dataframe created above across all years. Build out all years withn = 10/cty-yr and n = 5/cty-yr
ss2 <- function(df) {
use <- df %>%
group_by(GEOID, CROP) %>%
summarise(unique = length(unique((STPOID))),
max_wateruse_AF = max(WATER_AF),
max_yield_lbs = max(YIELD_LBS),
max_acres = max(ACRES_HARV),
total_weighted_acres = sum(w_ACRES_HARV)) %>%
filter(unique >= 6)
use_me <- merge(use, df, by = c("GEOID", "CROP"))
ss_panel <- use_me %>%
group_by(GEOID, CROP) %>%
summarise(sum_w_ACRES_HARV = sum(w_ACRES_HARV),
sum_w_HECTARES_HARV = sum(w_HECTARES_HARV),
sum_w_HARVESTED_LBS = sum(w_HARVESTED_LBS),
sum_w_HARVESTED_KG = sum(w_HARVESTED_KG),
sum_w_WU_AF = sum(w_WU_AF),
sum_w_WU_IN = sum(w_WU_IN),
sum_w_WU_CM = sum(w_WU_CM),
sum_w_WU_M = sum(w_WU_M),
EST_AVE_YIELD_LBS = sum_w_HARVESTED_LBS/sum_w_ACRES_HARV,
EST_AVE_YIELD_KG = sum_w_HARVESTED_KG/sum_w_HECTARES_HARV,
EST_AVE_WU_AF = sum_w_WU_AF/sum_w_ACRES_HARV,
EST_AVE_WU_IN = sum_w_WU_IN/sum_w_ACRES_HARV,
EST_AVE_WU_CM = sum_w_WU_CM/sum_w_HECTARES_HARV,
EST_AVE_WU_M = sum_w_WU_M/sum_w_HECTARES_HARV,
EST_IP_LBS_AF = EST_AVE_YIELD_LBS/EST_AVE_WU_AF, # estimated average pounds/acre foot
EST_IP_LBS_IN = EST_AVE_YIELD_LBS/EST_AVE_WU_IN, # estimated average pounds/cubic inch
EST_IP_KG_CM = EST_AVE_YIELD_KG/EST_AVE_WU_CM, # estimated average kg/cubic cm
EST_IP_KG_M = EST_AVE_YIELD_KG/EST_AVE_WU_M) %>% # estimated average kg/cubic m
select(GEOID, CROP, EST_AVE_YIELD_LBS, EST_AVE_YIELD_KG, EST_AVE_WU_AF, EST_AVE_WU_IN, EST_AVE_WU_CM, EST_AVE_WU_M, EST_IP_LBS_AF, EST_IP_LBS_IN, EST_IP_KG_CM, EST_IP_KG_M)
ss_panel <- merge(use, ss_panel, by = c("GEOID", "CROP"))
}
ip_allyears <- ss2(weighted)
#saveRDS(ip_allyears, "./out/DEER/sumstat_allyrs.RDS")
write.csv(ip_allyears, "./out/DEER/sumstat_allyrs.csv")
```
# Spatial Visualizations: Maps
Code chunk D): *Will rebuild with approved datasets outside the NORC!*
**DATA IN**: sumstat_allyrs.csv and western_ctys.RDS
With the county-level summary data I built in code chunks A), B), and C) we are first going to create county-level maps of estimated average yield, estimated average water use, and estimated irrigation productivity. I follow these steps and have annotated code chunk D) accordingly:
1) Bring in necesary packages, the spatial data for the western US (literally just counties with a "GEOID" column to merge with), built in step 1, and the sumstat_allyrs.csv datasets;
2) Merge the ctys dataframe with fris_sp_allyrs (summary statistics created above with *n* >= 6 unique county-crop observations);
3) Create two functions: one that I used to initially visualize the data with quantile style binning; and a second to create unique bin cut-offs for each that evenly break (on a zero), where the upper bound of the greatest bin is greater than the most extreme county value, and where the high end of each bin is at least 111% of the bins midpoint value. (It feels inconsistent and untruthful and wrong to leave the greatest bin unbounded, as Matt Fetter requested back in March. Feel free to reach out to discuss this.). These functions take on the following calls:
function_name(dataframe, "CROP", "VARIABLE OF INTEREST", c(BREAKS), "COLOR PALETTE", "TITLE", "./file_path/file_name.png")
All visualizations are directed to a specific folder and have unique filenames. The naming convention is as follows:"
file_name == crop_variable_units_map.png (e.g., alfalfa_yield_lbs_map.png, corngrain_wu_AF_map.png)
4) Build maps for estimated average yield in pounds/acre and kg/hectare;
5) Build maps for estimated average water applied/used in AF/acre, and cubic meters;
6) Build maps for estimated average irrigation productivity in AF/acre and kg/cubic meter.
```{r D) SPATIAL VISUALIZATIONS-IP-YIELD-WU, message = F, warning = F, eval=FALSE}
# Read in packages & data
library(sp)
library(spdplyr)
library(tmap)
library(rgdal)
library(RColorBrewer)
library(gridExtra)
library(ggplot2)
library(ggpubr)
library(rgeos)
# move ss_allyrs.csv and ss_indyrs.csv FROM out/DEER to the results folder
ctys <- readRDS("./data/western_ctys.RDS")
fris_sp_allyrs <- read.csv("./out/DEER/sumstat_allyrs.csv")
# Build spatial across crops using the panel dataset (summarizes across all years)
sp_allyrs_fris <- sp::merge(ctys, fris_sp_allyrs, by = "GEOID", duplicateGeoms = TRUE, all = TRUE)
# use to initially visualize the data -- determine bin cut-offs with a quantile style (each bin will have equal numbers of counties)
build_sp_allyrs <- function(df, crop, variable, colors, legend, place) {
x <- df %>%
filter(CROP == crop)
crop_yield_map <- tm_shape(ctys) + tm_polygons(col="grey", border.col = "white") +
tm_shape(x) +
tm_polygons(col= variable, style = "quantile", n = 6, palette = colors, border.col = "white",
legend.hist = TRUE, title = legend) +
tm_legend(outside = TRUE, hist.width = 1.5) +
tm_layout(frame= FALSE, legend.hist.size = 0.5)
tmap_save(crop_yield_map, place)
return(crop_yield_map)
}
# use to finalize the visualization of the data -- determine bin cut-offs with a quantile-esque style (each bin will have equal-ish numbers of counties). I say quantile-esque because I attempted to satisfy Matt Fetter's request that the top of each bin be 111% of the midpoint. I also pushed the top of the bin beyond the highest value. Matt asked that the top bin be unbounded.... but this feels entirely inconsistent and a bit of a data "lie".
build_sp_allyrs2 <- function(df, crop, variable, breaks, colors, legend, place) {
x <- df %>%
filter(CROP == crop)
crop_yield_map <- tm_shape(ctys) + tm_polygons(col="grey", border.col = "white") +
tm_shape(x) +
tm_polygons(col= variable, breaks = breaks, palette = colors, border.col = "white",
legend.hist = TRUE, title = legend) +
tm_legend(outside = TRUE, hist.width = 1.5) +
tm_layout(frame= FALSE, legend.hist.size = 0.5)
tmap_save(crop_yield_map, place)
return(crop_yield_map)
}
###################################################################################################################
### ESTIMATED AVERAGE YIELD
###################################################################################################################
### Estimated average yield across panel - US (lbs)
build_sp_allyrs2(sp_allyrs_fris, "ALFALFA", "EST_AVE_YIELD_LBS", c(4500,6250,7750,9500,11750,14500,26000), "Greens", "Average Estimated\nAlfalfa Yield\n(lbs/acre)", "./viz/mean_yield_panel/alfalfa_yield_lbs_map.png")
build_sp_allyrs2(sp_allyrs_fris, "OTHER_HAY", "EST_AVE_YIELD_LBS", c(1750,4000,5000,6500,8000,10000,20500), "Reds", "Average Estimated\nHay Yield\n(lbs/acre)", "./viz/mean_yield_panel/hay_yield_lbs_map.png")
build_sp_allyrs2(sp_allyrs_fris, "WHEAT", "EST_AVE_YIELD_LBS", c(2500,3250,4250,5250,6500,8000), "Oranges", "Average Estimated\nHay Yield\n(lbs/acre)", "./viz/mean_yield_panel/wheat_yield_lbs_map.png")
build_sp_allyrs2(sp_allyrs_fris, "CORN_GRAIN", "EST_AVE_YIELD_LBS", c(7000,8750,10750,14500), "Blues", "Average Estimated\nCorn Grain Yield\n(lbs/acre)", "./viz/mean_yield_panel/corngrain_yield_lbs_map.png")
build_sp_allyrs2(sp_allyrs_fris, "CORN_SILAGE", "EST_AVE_YIELD_LBS", c(11250,14500,17500,23000), "Purples", "Average Estimated\nCorn Silage Yield\n(lbs/acre)", "./viz/mean_yield_panel/cornsilage_yield_lbs_map.png")
###################################################################################################################
### Estimated average yield across panel - Metric (kg)
build_sp_allyrs2(sp_allyrs_fris, "ALFALFA", "EST_AVE_YIELD_KG", c(5000,7000,8500,10000,12000,15000,29000), "Greens", "Average Estimated\nAlfalfa Yield\n(kg/hectare)", "./viz/mean_yield_panel/alfalfa_yield5_kg_map.png")
build_sp_allyrs2(sp_allyrs_fris, "OTHER_HAY", "EST_AVE_YIELD_KG", c(2000,4000,5500,7000,9000,12000,23000), "Reds", "Average Estimated\nHay Yield\n(kg/hectare)", "./viz/mean_yield_panel/hay_yield5_kg_map.png")
build_sp_allyrs2(sp_allyrs_fris, "WHEAT", "EST_AVE_YIELD_KG", c(3000,4500,5500,6500,7500,8500), "Oranges", "Average Estimated\nWheat Yield\n(kg/hectare)", "./viz/mean_yield_panel/wheat_yield5_kg_map.png")
build_sp_allyrs2(sp_allyrs_fris, "CORN_GRAIN", "EST_AVE_YIELD_KG", c(8250,10000,11000,12000,13000,14000,16250), "Blues", "Average Estimated\nCorn Grain Yield\n(kg/hectare)", "./viz/mean_yield_panel/corngrain_yield5_kg_map.png")
build_sp_allyrs2(sp_allyrs_fris, "CORN_SILAGE", "EST_AVE_YIELD_KG", c(12500,18000,19000,20000,21500,23000, 26000), "Purples", "Average Estimated\nCorn Silage Yield\n(kg/hectare)", "./viz/mean_yield_panel/cornsilage_yield5_kg_map.png")
###################################################################################################################
### ESTIMATED AVERAGE WATER APPLICATION
###################################################################################################################
### Mean Water Application across panel - US
build_sp_allyrs2(sp_allyrs_fris, "ALFALFA", "EST_AVE_WU_AF", c(0.25,1.25,1.75,2.25,2.75,3.5,6.75), "Greens", "Estimated Average Water\nApplication in Alfalfa\n(acre feet/acre)", "./viz/mean_waterapplication_panel/alfalfa_wu_AF_map.png")
build_sp_allyrs2(sp_allyrs_fris, "OTHER_HAY", "EST_AVE_WU_AF", c(0.5,1.,1.5,2,2.5,3,5.25), "Reds", "Estimated Average Water\nApplication in Hay\n(acre feet/acre)", "./viz/mean_waterapplication_panel/hay_wu_AF_map.png")
build_sp_allyrs2(sp_allyrs_fris, "WHEAT", "EST_AVE_WU_AF", c(0.25,1.25,1.5,1.75,2,2.5,4.25), "Oranges", "Estimated Average Water\nApplication in Wheat\n(acre feet/acre)", "./viz/mean_waterapplication_panel/wheat_wu_AF_map.png")
build_sp_allyrs2(sp_allyrs_fris, "CORN_GRAIN", "EST_AVE_WU_AF", c(1,1.25,1.75,2.25,2.75,3.5,5), "Blues", "Estimated Average Water\nApplication in Corn Grain\n(acre feet/acre)", "./viz/mean_waterapplication_panel/corngrain_wu_AF_map.png")
build_sp_allyrs2(sp_allyrs_fris, "CORN_SILAGE", "EST_AVE_WU_AF", c(0.75,1.25,1.75,2.25,2.75,3.5,4.75), "Purples", "Estimated Average Water\nApplication in Corn Silage\n(acre feet/acre)", "./viz/mean_waterapplication_panel/cornsilage_wu_AF_map.png")
###################################################################################################################
### Mean Water Application across panel - Metric (m)
build_sp_allyrs2(sp_allyrs_fris, "ALFALFA", "EST_AVE_WU_M", c(2000,4000,5000,6500,8000,10000,20000), "Greens", "Estimated Average Water\nApplication in Alfalfa\n(cubic meters/hectare)", "./viz/mean_waterapplication_panel/alfalfa_wu5_M_map.png")
build_sp_allyrs2(sp_allyrs_fris, "OTHER_HAY", "EST_AVE_WU_M", c(1500,3500,4500,6000,7500,9000,15750), "Reds", "Estimated Average Water\nApplication in Hay\n(cubic meters/hectare)", "./viz/mean_waterapplication_panel/hay_wu5_M_map.png")
build_sp_allyrs2(sp_allyrs_fris, "WHEAT", "EST_AVE_WU_M", c(1250,3000,4000,5000,6000,8000,12250), "Oranges", "Estimated Average Water\nApplication in Wheat\n(cubic meters/hectare)", "./viz/mean_waterapplication_panel/wheat_wu5_M_map.png")
build_sp_allyrs2(sp_allyrs_fris, "CORN_GRAIN", "EST_AVE_WU_M", c(3500,4500,5500,6500,7500,9000,15250), "Blues", "Estimated Average Water\nApplication in Corn Grain\n(cubic meters/hectare)", "./viz/mean_waterapplication_panel/corngrain_wu5_M_map.png")
build_sp_allyrs2(sp_allyrs_fris, "CORN_SILAGE", "EST_AVE_WU_M", c(2500,4500,5500,6500,7500,9000,15000), "Purples", "Estimated Average Water\nApplication in Corn Silage\n(cubic meters/hectare)", "./viz/mean_waterapplication_panel/cornsilage_wu5_M_map.png")
###################################################################################################################
### IRRIGATION PRODUCTIVITY
###################################################################################################################
### Mean Irrigation Productivity across panel - US (pounds/acre foot)
build_sp_allyrs2(sp_allyrs_fris, "ALFALFA", "EST_IP_LBS_AF", c(2000,3000,4000,5000,6250,8000,23000), "Greens", "Estimated Average Irrigation\nProductivity in Alfalfa\n(pounds/acre foot)", "./viz/mean_ip_panel/alfalfa_ip_LBSperAF_map.png")
build_sp_allyrs2(sp_allyrs_fris, "OTHER_HAY", "EST_IP_LBS_AF", c(1000,2500,3250,4000,5000,6250,25500), "Reds", "Estimated Average Irrigation\nProductivity in Hay\n(pounds/acre foot)", "./viz/mean_ip_panel/hay_ip_LBSperAF_map.png")
build_sp_allyrs2(sp_allyrs_fris, "WHEAT", "EST_IP_LBS_AF", c(1000,2000,3000,3750,4000,5000,11000), "Oranges", "Estimated Average Irrigation\nProductivity in Wheat\n(pounds/acre foot)", "./viz/mean_ip_panel/wheat_ip_LBSperAF_map.png")
build_sp_allyrs2(sp_allyrs_fris, "CORN_GRAIN", "EST_IP_LBS_AF", c(1750,3000,4000,5000,6250,8000), "Blues", "Estimated Average Irrigation\nProductivity in Corn Grain\n(pounds/acre foot)", "./viz/mean_ip_panel/corngrain_ip_LBSperAF_map.png")
build_sp_allyrs2(sp_allyrs_fris, "CORN_SILAGE", "EST_IP_LBS_AF", c(4000,5000,6250,7500,9250,12000,20000), "Purples", "Estimated Average Irrigation\nProductivity in Corn Silage\n(pounds/acre foot)", "./viz/mean_ip_panel/cornsilage_ip_LBSperAF_map.png")
###################################################################################################################
### Mean Irrigation Productivity across panel - Metric (kg/m)
build_sp_allyrs2(sp_allyrs_fris, "ALFALFA", "EST_IP_KG_M", c(0.75,1,1.25,1.5,1.75,2.25,8.5), "Greens", "Estimated Average Irrigation\nProductivity in Alfalfa\n(kilograms/cubic meter)", "./viz/mean_ip_panel/alfalfa_ip5_KGperM_map.png")
build_sp_allyrs2(sp_allyrs_fris, "OTHER_HAY", "EST_IP_KG_M", c(0.25,0.75,1,1.25,1.5,2.25,9.5), "Reds", "Estimated Average Irrigation\nProductivity in Hay\n(kilograms/cubic meter)", "./viz/mean_ip_panel/hay_ip5_KGperM_map.png")
build_sp_allyrs2(sp_allyrs_fris, "WHEAT", "EST_IP_KG_M", c(0.25,0.75,1,1.25,1.5,1.75,4), "Oranges", "Estimated Average Irrigation\nProductivity in Wheat\n(kilograms/cubic meter)", "./viz/mean_ip_panel/wheat_ip5_KGperM_map.png")
build_sp_allyrs2(sp_allyrs_fris, "CORN_GRAIN", "EST_IP_KG_M", c(0.5,1.25,1.5,1.75,2,2.5,3), "Blues", "Estimated Average Irrigation\nProductivity in Corn Grain\n(kilograms/cubic meter)", "./viz/mean_ip_panel/corngrain_ip5_KGperM_map.png")
build_sp_allyrs2(sp_allyrs_fris, "CORN_SILAGE", "EST_IP_KG_M", c(1.5,2.25,2.75,3.25,3.75,4.5,7.25), "Purples", "Estimated Average Irrigation\nProductivity in Corn Silage\n(kilograms/cubic meter)", "./viz/mean_ip_panel/cornsilage_ip5_KGperM_map.png")
```
Code chunk E): *Will rebuild with approved datasets outside the NORC!*
**DATA**: sumstat_indyrs.csv and western_ctys.RDS
1) I build two functions (nearly identical to the functions built in step 3), code chunk D) for visualizing data specifically in 2018 using the sumstat_indyrs.csv datasets. These functions take on the following calls:
function_name(dataframe, "CROP", YEAR, "VARIABLE OF INTEREST", c(BREAKS), "COLOR PALETTE", "TITLE", "./file_path/file_name.png") and have the same naming convention as above.
2) Build maps for estimated average irrigation productivity in AF/acre and kg/cubic meter.
```{r E) SPATIAL VISUALIZATIONS-IP-2018, message = F, warning = F, eval=FALSE}
####################################################################################################################
### ESTIMATED AVERAGE IRRIGATION PRODUCTIVITY IN 2018
####################################################################################################################
# Build spatial across crops using the _indyrs datasets (summarizes across individual years)
fris_sp_indyrs <- read.csv("./out/DEER/sumstat_indyrs.csv")
sp_indyrs_fris <- sp::merge(ctys, fris_sp_indyrs, by = "GEOID", duplicateGeoms = TRUE, all = TRUE)
build_sp_indyrs <- function(df, crop, year, variable, colors, legend, place) {
x <- df %>%
filter(CROP == crop) %>%
filter(YEAR == year)
crop_ip_map <- tm_shape(ctys) + tm_polygons(col="grey", border.col = "white") +
tm_shape(x) +
tm_polygons(col=variable, style = "quantile", n = 6, palette = colors, border.col = "white",
legend.hist = TRUE, title = legend) +
tm_legend(outside = TRUE, hist.width = 1.5) +
tm_layout(frame= FALSE, legend.hist.size = 0.5)
tmap_save(crop_ip_map, place)
return(crop_ip_map)
}
build_sp_indyrs2 <- function(df, crop, year, variable, breaks, colors, legend, place) {
x <- df %>%
filter(CROP == crop) %>%
filter(YEAR == year)
crop_ip_map <- tm_shape(ctys) + tm_polygons(col="grey", border.col = "white") +
tm_shape(x) +
tm_polygons(col=variable, breaks = breaks, palette = colors, border.col = "white",
legend.hist = TRUE, title = legend) +
tm_legend(outside = TRUE, hist.width = 1.5) +
tm_layout(frame= FALSE, legend.hist.size = 0.5)
tmap_save(crop_ip_map, place)
return(crop_ip_map)
}
###################################################################################################################
### Irrigation Productivity in 2018 - US (pounds/AF)
build_sp_indyrs2(sp_indyrs_fris, "ALFALFA", 2018, "EST_IP_LBS_AF", c(2000,3000,3750,4750,5750,7250,16250), "Greens", "Estimated Average Irrigation\nProductivity in Alfalfa\n(pounds/acre foot)", "./viz/mean_ip_2018/alfalfa_ip_LBSperAF_map.png")
build_sp_indyrs2(sp_indyrs_fris, "OTHER_HAY", 2018, "EST_IP_LBS_AF", c(1250,2250,2750,3500,4500,5500,13000), "Reds", "Estimated Average Irrigation\nProductivity in Hay\n(pounds/acre foot)", "./viz/mean_ip_2018/hay_ip_LBSperAF_map.png")
build_sp_indyrs2(sp_indyrs_fris, "WHEAT", 2018, "EST_IP_LBS_AF", c(1500,2000,2750,3500,4500,5500,8500), "Oranges", "Estimated Average Irrigation\nProductivity in Wheat\n(pounds/acre foot)", "./viz/mean_ip_2018/wheat_ip_LBSperAF_map.png")
build_sp_indyrs2(sp_indyrs_fris, "CORN_GRAIN", 2018, "EST_IP_LBS_AF", c(3000,3750,4750,6000,7500,9250), "Blues", "Estimated Average Irrigation\nProductivity in Corn Grain\n(pounds/acre foot)", "./viz/mean_ip_2018/corngrain_ip_LBSperAF_map.png")
build_sp_indyrs2(sp_indyrs_fris, "CORN_SILAGE", 2018, "EST_IP_LBS_AF", c(4000,6000,7500,9250,12000,17500), "Purples", "Estimated Average Irrigation\nProductivity in Corn Silage\n(pounds/acre foot)", "./viz/mean_ip_2018/cornsilage_ip_LBSperAF_map.png")
###################################################################################################################
### Irrigation Productivity in 2018 - Metric (cubic meters/hectare)
build_sp_indyrs2(sp_indyrs_fris, "ALFALFA", 2018, "EST_IP_KG_M", c(0.75,1.25,1.5,1.75,2.25,2.75,6.0), "Greens", "Estimated Average Irrigation\nProductivity in Alfalfa\n(kilograms/cubic meter)", "./viz/mean_ip_2018/alfalfa_ip_KGperM_map.png")
build_sp_indyrs2(sp_indyrs_fris, "OTHER_HAY", 2018, "EST_IP_KG_M", c(0.25,0.75,1,1.25,1.5,2,4.75), "Reds", "Estimated Average Irrigation\nProductivity in Hay\n(kilograms/cubic meter)", "./viz/mean_ip_2018/hay_ip_KGperM_map.png")
build_sp_indyrs2(sp_indyrs_fris, "WHEAT", 2018, "EST_IP_KG_M", c(0.5,0.75,1,1.25,1.5,1.75,3.25), "Oranges", "Estimated Average Irrigation\nProductivity in Wheat\n(kilograms/cubic meter)", "./viz/mean_ip_2018/wheat_ip_KGperM_map.png")
build_sp_indyrs2(sp_indyrs_fris, "CORN_GRAIN", 2018, "EST_IP_KG_M", c(1,1.25,1.5,1.75,2,2.5,3.25), "Blues", "Estimated Average Irrigation\nProductivity in Corn Grain\n(kilograms/cubic meter)", "./viz/mean_ip_2018/corngrain_ip_KGperM_map.png")
build_sp_indyrs2(sp_indyrs_fris, "CORN_SILAGE", 2018, "EST_IP_KG_M", c(1.5,2.25,2.75,3.25,3.75,4.5,6.5), "Purples", "Estimated Average Irrigation\nProductivity in Corn Silage\n(kilograms/cubic meter)", "./viz/mean_ip_2018/cornsilage_ip_KGperM_map.png")
```
Code chunk F): *Will rebuild with approved datasets outside the NORC!*
**DATA**: sumstat_indyrs.csv and western_ctys.RDS
Below, I am interested in finding the differences in estimated average yield, estimated average water application/use, and estimated average irrigation productivity between 2018 (normal year in rainfall) and 2013 (drought year across the west). We want to see how responsive irrigation is to differences in rainfall. So the code works as follows:
1) I build a dataset that merges filtered data from ONLY 2018 and 2013 from the fris_sp_indyrs and fris5_Sp_indyrs dataframes. I then bind/merge these data with our ctys spatial layer so that we can map differences between 2013 and 2018;
2) I build two functions, again, where the first is used to visualize the data in strict quantiles and the second is used to build unique bins using Matt Fetter's criteria. This function mutates new columns into the spatial dataframe that are: 2013_variable - 2018_variable. For example, if the resulting value in the mutated water use column is positive, less water was put on it 2018 than in 2013. I feed the function a "RdBu" palette to visualize differences.;
3) Build maps for estimated average water applied/used in AF/acre and cubic meters;
4) Build maps for estimated average yield in pounds/acre and kg/hectare;
5) Build maps for estimated average irrigation productivity in AF/acre and kg/cubic meter.
```{r F) SPATIAL VISUALIZATIONS-IP-YIELD-WU_DIFFERENCE, message = F, warning = F, eval=FALSE}
######################################################################################################################## DIFFERENCe IN MEAN IP, ESTIMATED AVERAGE YIELD, & ESTIMATED AVERAGE WATER USE BETWEEN 2013 & 2018!
####################################################################################################################
# Build spatial across crops using the _indyrs dataset (summarizes across individual years)
# build-out difference in mean IP/WA/Y between 2013 and 2018
# n >= 10 observations/cty-yr
# to find differences, use code within function, below
# build spatial
sp_diff <- sp::merge(ctys, y, by = "GEOID", duplicateGeoms = TRUE, all = TRUE)
# build spatial differences maps
build_sp_diff <- function(df, crop, variable, legend, place) {
x <- df %>%
filter(CROP == crop) %>%
mutate(yield_diff_LBS = (EST_AVE_YIELD_LBS.y - EST_AVE_YIELD_LBS.x), # yield (pounds/acre)
yield_diff_KG = (EST_AVE_YIELD_KG.y - EST_AVE_YIELD_KG.x), # yield (kg/hectare)
wa_diff_AF = (EST_AVE_WU_AF.y - EST_AVE_WU_AF.x), # water applied (acre feet/acre)
wa_diff_M = (EST_AVE_WU_M.y - EST_AVE_WU_M.x), # water applied (cubic meter/hectare)
ip_diff_LBSAF = (EST_IP_LBS_AF.y - EST_IP_LBS_AF.x), # irrigation productivity (pounds / AF)
ip_diff_KGM = (EST_IP_KG_M.y - EST_IP_KG_M.x)) # irrigation productivity (kg / cubic meter)
crop_map <- tm_shape(ctys) + tm_polygons(col="grey", border.col = "white") +
tm_shape(x) +
tm_polygons(col= variable, style = "quantile", n = 6, palette = "RdBu", border.col = "white",
legend.hist = TRUE, title = legend) +
tm_legend(outside = TRUE, hist.width = 1.5) +
tm_layout(frame= FALSE, legend.hist.size = 0.5)
tmap_save(crop_map, place)
return(crop_map)
}
# build spatial differences maps ~ custom breaks
build_sp_diff2 <- function(df, crop, variable, breaks, palette, legend, place) {
x <- df %>%
filter(CROP == crop) %>%
mutate(yield_diff_LBS = (EST_AVE_YIELD_LBS.y - EST_AVE_YIELD_LBS.x), # yield (pounds/acre)
yield_diff_KG = (EST_AVE_YIELD_KG.y - EST_AVE_YIELD_KG.x), # yield (kg/hectare)
wa_diff_AF = (EST_AVE_WU_AF.y - EST_AVE_WU_AF.x), # water applied (acre feet/acre)
wa_diff_M = (EST_AVE_WU_M.y - EST_AVE_WU_M.x), # water applied (cubic meter/hectare)
ip_diff_LBSAF = (EST_IP_LBS_AF.y - EST_IP_LBS_AF.x), # irrigation productivity (pounds / AF)
ip_diff_KGM = (EST_IP_KG_M.y - EST_IP_KG_M.x)) # irrigation productivity (kg / cubic meter)
crop_map <- tm_shape(ctys) + tm_polygons(col="grey", border.col = "white") +
tm_shape(x) +
tm_polygons(col= variable, breaks = breaks, palette = palette, border.col = "white",
legend.hist = TRUE, title = legend) +
tm_legend(outside = TRUE, hist.width = 1.5) +
tm_layout(frame= FALSE, legend.hist.size = 0.5)
tmap_save(crop_map, place)
return(crop_map)
}
####################################################################################################################
###### ESTIMATED AVERAGE WATER APPLIED
####################################################################################################################
### Differences in water applied between 2018 (normal year) and 2013 (drought year)
# Average Estimated Water Applied - US AF/acre
build_sp_diff2(sp_diff, "ALFALFA", "wa_diff_AF", c(-2.5,-0.75,-0.5,-0.25,0,0.25,0.5,1,2.5), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#92C5DE", "#4393C3", "#2166AC"), "Difference in Water\nApplied in Alfalfa\n(acre feet/acre)", "./viz/mean_diff_waterapplication/alfalfa_diffAF_map.png")
build_sp_diff2(sp_diff, "OTHER_HAY", "wa_diff_AF", c(-1,-0.5,-0.25,0,0.25,0.5,1,2.5), c("#B2182B", "#EF8A62", "#FDDBC7", "#D1E5F0", "#92C5DE", "#4393C3", "#2166AC"), "Difference in Water\n Applied in Hay\n(acre feet/acre)", "./viz/mean_diff_waterapplication/hay_diffAF_map.png")
build_sp_diff2(sp_diff, "WHEAT", "wa_diff_AF", c(-1.5,-0.5,-0.25,0,0.25,0.5,0.75), c("#B2182B", "#EF8A62", "#FDDBC7", "#D1E5F0", "#67A9CF", "#2166AC"), "Difference in Water\nApplied in Wheat\n(acre feet/acre)", "./viz/mean_diff_waterapplication/wheat_diffAF_map.png")
build_sp_diff2(sp_diff, "CORN_GRAIN", "wa_diff_AF", c(-1.5,-0.5,-0.25,0,0.25,0.5,0.75), c("#B2182B", "#EF8A62", "#FDDBC7", "#D1E5F0", "#67A9CF", "#2166AC"), "Difference in Water\nApplied in Corn Grain\n(acre feet/acre)", "./viz/mean_diff_waterapplication/corngrain_diffAF_map.png")
build_sp_diff2(sp_diff, "CORN_SILAGE", "wa_diff_AF", c(-2.25,-0.5,-0.25,0,0.25,0.5,0.75,1.25), c("#B2182B", "#EF8A62", "#FDDBC7", "#D1E5F0", "#92C5DE", "#4393C3", "#2166AC"), "Difference in Water\nApplied in Corn Silage\n(acre feet/acre)", "./viz/mean_diff_waterapplication/cornsilage_diffAF_map.png")
####################################################################################################################
# Average Estimated Water Applied - Metric cubic m/hectare
build_sp_diff2(sp_diff, "ALFALFA", "wa_diff_M", c(-7000,-2500,-1500,-500,0,1000,2000,4000, 7250), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#92C5DE", "#4393C3", "#2166AC"), "Difference in Water\nApplied in Alfalfa\n(cubic meters/hectare)", "./viz/mean_diff_waterapplication/alfalfa_diffM_map.png")
build_sp_diff2(sp_diff, "OTHER_HAY", "wa_diff_M", c(-2750,-2000,-1000,-500,0,1000,2000,3000,7000), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#92C5DE", "#4393C3", "#2166AC"), "Difference in Water\nApplied in Hay\n(cubic meters/hectare)", "./viz/mean_diff_waterapplication/hay_diffM_map.png")
build_sp_diff2(sp_diff, "WHEAT", "wa_diff_M", c(-4250,-1500,-500,0,1000,1500, 2250), c("#B2182B", "#EF8A62", "#FDDBC7", "#D1E5F0", "#67A9CF", "#2166AC"), "Difference in Water\nApplied in Wheat\n(cubic meters/hectare)", "./viz/mean_diff_waterapplication/wheat_diffM_map.png")
build_sp_diff2(sp_diff, "CORN_GRAIN", "wa_diff_M", c(-4250,-2500,-1000,0,500,1000,1750), c("#B2182B", "#EF8A62", "#FDDBC7", "#D1E5F0", "#67A9CF", "#2166AC"), "Difference in Water\nApplied in Corn Grain\n(cubic meters/hectare)", "./viz/mean_diff_waterapplication/corngrain_diffM_map.png")
build_sp_diff2(sp_diff, "CORN_SILAGE", "wa_diff_M", c(-6500,-2000,-1000,0,1000,2000,3000,3750), c("#B2182B", "#EF8A62", "#FDDBC7", "#D1E5F0", "#92C5DE", "#4393C3", "#2166AC"), "Difference in Water\nApplied in Corn Silage\n(cubic meters/hectare)", "./viz/mean_diff_waterapplication/cornsilage_diffM_map.png")
####################################################################################################################
###### ESTIMATED AVERAGE YIELD
####################################################################################################################
# Average Estimated Yield - US lbs/acre
build_sp_diff2(sp_diff, "ALFALFA", "yield_diff_LBS", c(-6000,-2000,-1000,0,1000,2000,4000), c("#B2182B", "#EF8A62", "#FDDBC7", "#D1E5F0", "#67A9CF", "#2166AC"), "Difference in Yield \nin Alfalfa (pounds/acre)", "./viz/mean_diff_yield/alfalfa_diffLBS_map.png")
build_sp_diff2(sp_diff, "OTHER_HAY", "yield_diff_LBS", c(-8500,-2000,-1000,-500,0,500,1000,2000,3250), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#92C5DE", "#4393C3", "#2166AC"), "Difference in Yield \nin Hay (pounds/acre)", "./viz/mean_diff_yield/hay_diffLBS_map.png")
build_sp_diff2(sp_diff, "WHEAT", "yield_diff_LBS", c(-3750,-2000,-1000, -500,0,500,750,1750), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#92C5DE", "#2166AC"), "Difference in Yield \nin Wheat (pounds/acre)", "./viz/mean_diff_yield/wheat_diffLBS_map.png")
build_sp_diff2(sp_diff, "CORN_GRAIN", "yield_diff_LBS", c(-4000,-2500,-2000,-1500,-500,0,500,1250), c("#67001F", "#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#2166AC"), "Difference in Yield\nin Corn Grain\n(pounds/acre)", "./viz/mean_diff_yield/corngrain_diffLBS_map.png")
build_sp_diff2(sp_diff, "CORN_SILAGE", "yield_diff_LBS", c(-4500,-2500,-500,0,500,2000,4000), c("#B2182B", "#EF8A62", "#FDDBC7", "#D1E5F0", "#67A9CF", "#2166AC"), "Difference in Yield\nin Corn Silage\n(pounds/acre)", "./viz/mean_diff_yield/cornsilage_diffLBS_map.png")
####################################################################################################################
# Average Estimated Yield - Metric kg/hectare
build_sp_diff2(sp_diff, "ALFALFA", "yield_diff_KG", c(-6000,-2000,-1000,-500,0,500,1000,2000,4500), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#92C5DE", "#4393C3", "#2166AC"), "Difference in Yield\nin Alfalfa (kilograms/\nhectare)", "./viz/mean_diff_yield/alfalfa_diffKG_map.png")
build_sp_diff2(sp_diff, "OTHER_HAY", "yield_diff_KG", c(-9500,-2000, -1000,-500,0,500,1500,3500), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#92C5DE", "#2166AC"), "Difference in Yield\nin Hay (kilograms/\nhectare)", "./viz/mean_diff_yield/hay_diffKG_map.png")
build_sp_diff2(sp_diff, "WHEAT", "yield_diff_KG", c(-3000,-1500,-1000,-350,0,650,1000,1750), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#92C5DE", "#2166AC"), "Difference in Yield\nin Wheat (kilograms/\nhectare)", "./viz/mean_diff_yield/wheat_diffKG_map.png")
build_sp_diff2(sp_diff, "CORN_GRAIN", "yield_diff_KG", c(-4250,-2500,-2250,-1750,-750,0,750,1250), c("#67001F", "#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#2166AC"),"Difference in Yield\nin Corn Grain\n(kilograms/hectare)", "./viz/mean_diff_yield/corngrain_diffKG_map.png")
build_sp_diff2(sp_diff, "CORN_SILAGE", "yield_diff_KG", c(-5000,-3000,-2500,-500,0,1000,3000,4250), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#92C5DE", "#2166AC"), "Difference in Yield\nin Corn Silage\n(kilograms/hectare)", "./viz/mean_diff_yield/cornsilage_diffKG_map.png")
####################################################################################################################
###### IRRIGATION PRODUCTIVITY
####################################################################################################################
# Average Estimated Irrigation Productivity - US lbs/acre foot
build_sp_diff2(sp_diff, "ALFALFA", "ip_diff_LBSAF", c(-7750,-3000,-2000,-500,0,500,1000,2000,8500), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#92C5DE", "#4393C3", "#2166AC"), "Difference in Irrigation\nProductivity in Alfalfa\n(pounds/acre foot)", "./viz/mean_diff_ip/alfalfa_diffLBSAF_map.png")
build_sp_diff2(sp_diff, "OTHER_HAY", "ip_diff_LBSAF", c(-7500,-3000,-1000,-500,0,500,1000,2750), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#92C5DE", "#2166AC"), "Difference in Irrigation\nProductivity in Hay\n(pounds/acre foot)", "./viz/mean_diff_ip/hay_diffLBSAF_map.png")
build_sp_diff2(sp_diff, "WHEAT", "ip_diff_LBSAF", c(-3500,-1500,-500,0,250,750,1750), c("#B2182B", "#EF8A62", "#FDDBC7", "#D1E5F0", "#67A9CF", "#2166AC"), "Difference in Irrigation\nProductivity in Wheat\n(pounds/acre foot)", "./viz/mean_diff_ip/wheat_diffLBSAF_map.png")
build_sp_diff2(sp_diff, "CORN_GRAIN", "ip_diff_LBSAF", c(-2750,-1250,-750,-250,0,500,2250), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#2166AC"), "Difference in Irrigation\nProductivity in Corn Grain\n(pounds/acre foot)", "./viz/mean_diff_ip/corngrain_diffLBSAF_map.png")
build_sp_diff2(sp_diff, "CORN_SILAGE", "ip_diff_LBSAF", c(-8500,-4000,-2000,-1000,0,1000,2000,2250), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#92C5DE", "#2166AC"), "Difference in Irrigation\nProductivity in Corn Silage\n(pounds/acre foot)", "./viz/mean_diff_ip/cornsilage_diffLBSAF_map.png")
####################################################################################################################
# Average Estimated Irrigation Productivity - Metric kg/M
build_sp_diff2(sp_diff, "ALFALFA", "ip_diff_KGM", c(-3.0,-1.5,-0.75,-0.25,0,0.25,0.5,1,3.25), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#92C5DE", "#4393C3", "#2166AC"), "Difference in Irrigation\nProductivity in Alfalfa\n(kilograms/cubic meter)", "./viz/mean_diff_ip/alfalfa_diffKGM_map.png")
build_sp_diff2(sp_diff, "OTHER_HAY", "ip_diff_KGM", c(-2.75,-1.5,-0.5,-0.25,0,0.25,0.75,1), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#92C5DE", "#2166AC"), "Difference in Irrigation\nProductivity in Hay\n(kilograms/cubic meter)", "./viz/mean_diff_ip/hay_diffKGM_map.png")
build_sp_diff2(sp_diff, "WHEAT", "ip_diff_KGM", c(-1.25,-0.5,-0.25,0,0.25,0.5,0.75), c("#B2182B", "#EF8A62", "#FDDBC7", "#D1E5F0", "#67A9CF", "#2166AC"), "Difference in Irrigation\nProductivity in Wheat\n(kilograms/cubic meter)", "./viz/mean_diff_ip/wheat_diffKGM_map.png")
build_sp_diff2(sp_diff, "CORN_GRAIN", "ip_diff_KGM", c(-1,-0.75,-0.5,-0.25,0,0.25,1), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#2166AC"), "Difference in Irrigation\nProductivity in Corn Grain\n(kilograms/cubic meter)", "./viz/mean_diff_ip/corngrain_diffKGM_map.png")
build_sp_diff2(sp_diff, "CORN_SILAGE", "ip_diff_KGM", c(-3.25,-2,-1,-0.5,0,0.5,1), c("#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#D1E5F0", "#2166AC"), "Difference in Irrigation\nProductivity in Corn Silage\n(kilograms/cubic meter)", "./viz/mean_diff_ip/cornsilage_diffKGM_map.png")
```
# Trends
Code chunk G): *Will rebuild with approved datasets outside the NORC!*
**DATA**: sumstat_indyrs.csv and western_ctys.RDS
Let's show trends in Estimated Average Yield, Water Use, and Irrigation Productivity over time. These trends are built from the sum_stat_indyrs_X.RDS datasets and are built as line graphs, facetted by state. I am STILL using the same *key variables* (yield, water use).
1) Pull in datasets (again!) selecting only those county-year-crop combinations that show up across all four FRIS years. We will then merge these datasets (have only GEOID as a county identifier) with a distinct() version of the FRIS (has COUNTY_ALPHA, STATE_ABBR). This ensures that we have a "County, State Abbreviation" column to use in our visualizations, below.;
2) I then build two functions for irrigation productivity. I had to do this because my functions were failing to accept new parameters. The first function builds out a line graph by crop-county-year by state for each metric; the third function builds out by crop-county-year but not by state. I use the third and fourth function to build line graphs for crops that have too few observations to warrant visualization by state.;
These functions take the arguments:
function(data_frame, "CROP", "STATE AABREVIATION", "TITLE--always blank", "Y Axis Label", "./file_path/file_name.png")
Visualizations are sent to crop-specific folders within variable specific trend folders and are built for both metric and US (same graph, different scale) measurements.
Below is a whole lot of code, but its all doing the same exact action on different datasets and different variables and spitting out the results into nested crop-specific and variable-specific folders! Everything below works on estimated average, summarised data--NO raw data is visualized. We are trying to get a sense here of how these different variables change and vary spatially and temporally.
```{r G) TEMPORAL TRENDS VISUALIZATIONS, warning = FALSE, message = FALSE, eval=FALSE}
# Build line graph over time using the _indyrs datasets (to show trends over time)
library(RColorBrewer)
fris_sp_indyrs <- read.csv("./out/DEER/sumstat_indyrs.csv")
fris_sp_indyrs$GEOID <- sprintf("%05d", fris_sp_indyrs$GEOID)
# find counties in both datasets that have data across all four years of the fris for different crops
trends_fris <- fris_sp_indyrs %>%
mutate(count = 1) %>%
group_by(GEOID, CROP) %>%
summarise(count_yrs = sum(count)) %>%
filter(count_yrs == 4)
# We will use the above as a key to pull data from fris_sp_indyrs and fris5_sp_indyrs, keeping only those county-crop combinations where there are observations in all four years
trends_fris <- merge(trends_fris, fris_sp_indyrs, by = c("GEOID", "CROP"))
# the dataframes above have only county-crop combinations where there is an observation in each year.
# let's merge them with our full-panel-FRIS.RDS to build in a county name identifier
fris <- readRDS("./data/full-panel-FRIS.RDS")
fris_names <- fris %>%
select(GEOID, COUNTY_ALPHA, STATE_ABBR) %>%
distinct()
# Convert County name to title case
library(stringr)
fris_names$COUNTY_ALPHA = str_to_title(fris_names$COUNTY_ALPHA)
fris_names <- transform(fris_names, County = paste(COUNTY_ALPHA, STATE_ABBR, sep= ", "))
# give these df the pretty names from above!
trends_fris <- merge(trends_fris, fris_names, by = "GEOID")
####################################################################################################################
####### Build functions
####################################################################################################################
# build line graph by crop-county BY STATE
build_trends <- function(df, crop, abbr, var, ylab, place) {
x <- df %>%
filter(CROP == crop) %>%
filter(STATE_ABBR == abbr)
var <- enquo(var)
crop_trends <- ggplot(x, aes(x = YEAR, y = !! var)) +
geom_point(size = 3, aes(color = County)) +
geom_line(aes(color = County)) +
scale_color_brewer(palette = "Paired") +
#guides(col=guide_legend(ncol=2)) +
xlab("Year") +
ylab(ylab) +
scale_x_continuous(breaks = seq(2003, 2018, by = 5)) +
theme_classic()
ggsave(place, width=6, height=4,dpi=300, units="in", device='png')
return(crop_trends)
}
# build line graph by crop-county BY STATE (NO PALLETE + 2 column legend)
build_trendsa <- function(df, crop, abbr, var, ylab, place) {
x <- df %>%
filter(CROP == crop) %>%
filter(STATE_ABBR == abbr)
var <- enquo(var)
crop_trends <- ggplot(x, aes(x = YEAR, y = !! var)) +
geom_point(size = 3, aes(color = County)) +
geom_line(aes(color = County)) +
#scale_color_brewer(palette = "Paired") +
guides(col=guide_legend(ncol=2)) +
xlab("Year") +
ylab(ylab) +
scale_x_continuous(breaks = seq(2003, 2018, by = 5)) +
theme_classic()
ggsave(place, width=6, height=4,dpi=300, units="in", device='png')
return(crop_trends)
}
####################################################################################################################
####### Irrigation Productivity (Metric)
####################################################################################################################
######## ALFALFA
build_trends(trends_fris, "ALFALFA", "AZ", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/alfalfa/AZ_ip.png")
build_trends(trends_fris, "ALFALFA", "CA", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/alfalfa/CA_ip.png")
build_trends(trends_fris, "ALFALFA", "CO",EST_IP_KG_M,"Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/alfalfa/CO_ip.png")
build_trendsa(trends_fris, "ALFALFA", "ID",EST_IP_KG_M,"Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/alfalfa/ID_ip.png") ## too many counties for palette, use alternate function
build_trends(trends_fris, "ALFALFA", "MT",EST_IP_KG_M,"Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/alfalfa/MT_ip.png")
build_trends(trends_fris, "ALFALFA", "NV",EST_IP_KG_M,"Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/alfalfa/NV_ip.png")
build_trends(trends_fris, "ALFALFA", "NM",EST_IP_KG_M,"Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/alfalfa/NM_ip.png")
build_trends(trends_fris, "ALFALFA", "OR",EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/alfalfa/OR_ip.png")
build_trendsa(trends_fris, "ALFALFA", "UT",EST_IP_KG_M,"Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/alfalfa/UT_ip.png") ## too many counties for palette, use alternate function
build_trends(trends_fris, "ALFALFA", "WA",EST_IP_KG_M,"Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/alfalfa/WA_ip.png")
build_trends(trends_fris, "ALFALFA", "WY",EST_IP_KG_M,"Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/alfalfa/WY_ip.png")
######## HAY
build_trends(trends_fris, "OTHER_HAY", "AZ", EST_IP_KG_M,"Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/hay/AZ_ip.png")
build_trends(trends_fris, "OTHER_HAY", "CA", EST_IP_KG_M,"Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/hay/CA_ip.png")
build_trends(trends_fris, "OTHER_HAY", "CO", EST_IP_KG_M,"Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/hay/CO_ip.png")
build_trends(trends_fris, "OTHER_HAY", "ID", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/hay/ID_ip.png")
build_trends(trends_fris, "OTHER_HAY", "MT", EST_IP_KG_M,"Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/hay/MT_ip.png")
build_trends(trends_fris, "OTHER_HAY", "NV", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/hay/NV_ip.png")
build_trends(trends_fris, "OTHER_HAY", "OR", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/hay/OR_ip.png")
build_trends(trends_fris, "OTHER_HAY", "UT", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/hay/UT_ip.png")
build_trends(trends_fris, "OTHER_HAY", "WA", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/hay/WA_ip.png")
build_trends(trends_fris, "OTHER_HAY", "WY", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/hay/WY_ip.png")
##### WHEAT
build_trends(trends_fris, "WHEAT", "AZ",EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/wheat/AZ_ip.png")
build_trends(trends_fris, "WHEAT", "CA",EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/wheat/CA_ip.png")
build_trends(trends_fris, "WHEAT", "CO",EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/wheat/CO_ip.png")
build_trends(trends_fris, "WHEAT", "ID",EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/wheat/ID_ip.png")
build_trends(trends_fris, "WHEAT", "OR",EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/wheat/OR_ip.png")
build_trends(trends_fris, "WHEAT", "UT",EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/wheat/UT_ip.png")
build_trends(trends_fris, "WHEAT", "WA",EST_IP_KG_M,"Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/wheat/WA_ip.png")
##### Corn Grain
build_trends(trends_fris, "CORN_GRAIN", "CA", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/corngrain/CA_ip.png")
build_trends(trends_fris, "CORN_GRAIN", "CO", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/corngrain/CO_ip.png")
build_trends(trends_fris, "CORN_GRAIN", "ID", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/corngrain/ID_ip.png")
build_trends(trends_fris, "CORN_GRAIN", "OR", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/corngrain/OR_ip.png")
build_trends(trends_fris, "CORN_GRAIN", "WA", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/corngrain/WA_ip.png")
##### Corn Silage
build_trends(trends_fris, "CORN_SILAGE", "AZ", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/cornsilage/AZ_ip.png")
build_trends(trends_fris, "CORN_SILAGE", "CA", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/cornsilage/CA_ip.png")
build_trends(trends_fris, "CORN_SILAGE", "CO", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/cornsilage/CO_ip.png")
build_trends(trends_fris, "CORN_SILAGE", "ID", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/cornsilage/ID_ip.png")
build_trends(trends_fris, "CORN_SILAGE", "NM", EST_IP_KG_M,"Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/cornsilage/NM_ip.png")
build_trends(trends_fris, "CORN_SILAGE", "OR", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/cornsilage/OR_ip.png")
build_trends(trends_fris, "CORN_SILAGE", "UT", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/cornsilage/UT_ip.png")
build_trends(trends_fris, "CORN_SILAGE", "WA", EST_IP_KG_M, "Irrigation Productivity (kilograms/cubic meter)", "./viz/trends_ip/cornsilage/WA_ip.png")
####################################################################################################################
####### Irrigation Productivity (US)
####################################################################################################################
######## ALFALFA
build_trends(trends_fris, "ALFALFA", "AZ", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/alfalfa/AZ_ip_US.png")
build_trends(trends_fris, "ALFALFA", "CA", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/alfalfa/CA_ip_US.png")
build_trends(trends_fris, "ALFALFA", "CO", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/alfalfa/CO_ip_US.png")
build_trendsa(trends_fris, "ALFALFA", "ID", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/alfalfa/ID_ip_US.png") ## too many counties for palette, use alternate function
build_trends(trends_fris, "ALFALFA", "MT", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/alfalfa/MT_ip_US.png")
build_trends(trends_fris, "ALFALFA", "NV", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/alfalfa/NV_ip_US.png")
build_trends(trends_fris, "ALFALFA", "NM", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/alfalfa/NM_ip_US.png")
build_trends(trends_fris, "ALFALFA", "OR", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/alfalfa/OR_ip_US.png")
build_trendsa(trends_fris, "ALFALFA", "UT", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/alfalfa/UT_ip_US.png") ## too many counties for palette, use alternate function
build_trends(trends_fris, "ALFALFA", "WA", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/alfalfa/WA_ip_US.png")
build_trends(trends_fris, "ALFALFA", "WY", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/alfalfa/WY_ip_US.png")
######## HAY
build_trends(trends_fris, "OTHER_HAY", "AZ", EST_IP_LBS_AF,"Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/hay/AZ_ip_US.png")
build_trends(trends_fris, "OTHER_HAY", "CA", EST_IP_LBS_AF,"Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/hay/CA_ip_US.png")
build_trends(trends_fris, "OTHER_HAY", "CO", EST_IP_LBS_AF,"Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/hay/CO_ip_US.png")
build_trends(trends_fris, "OTHER_HAY", "ID", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/hay/ID_ip_US.png")
build_trends(trends_fris, "OTHER_HAY", "MT", EST_IP_LBS_AF,"Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/hay/MT_ip_US.png")
build_trends(trends_fris, "OTHER_HAY", "NV", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/hay/NV_ip_US.png")
build_trends(trends_fris, "OTHER_HAY", "OR", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/hay/OR_ip_US.png")
build_trends(trends_fris, "OTHER_HAY", "UT", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/hay/UT_ip_US.png")
build_trends(trends_fris, "OTHER_HAY", "WA", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/hay/WA_ip_US.png")
build_trends(trends_fris, "OTHER_HAY", "WY", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/hay/WY_ip_US.png")
##### WHEAT
build_trends(trends_fris, "WHEAT", "AZ",EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/wheat/AZ_ip_US.png")
build_trends(trends_fris, "WHEAT", "CA",EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/wheat/CA_ip_US.png")
build_trends(trends_fris, "WHEAT", "CO",EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/wheat/CO_ip_US.png")
build_trends(trends_fris, "WHEAT", "ID",EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/wheat/ID_ip_US.png")
build_trends(trends_fris, "WHEAT", "OR",EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/wheat/OR_ip_US.png")
build_trends(trends_fris, "WHEAT", "UT",EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/wheat/UT_ip_US.png")
build_trends(trends_fris, "WHEAT", "WA",EST_IP_LBS_AF,"Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/wheat/WA_ip_US.png")
##### Corn Grain
build_trends(trends_fris, "CORN_GRAIN", "CA", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/corngrain/CA_ip_US.png")
build_trends(trends_fris, "CORN_GRAIN", "CO", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/corngrain/CO_ip_US.png")
build_trends(trends_fris, "CORN_GRAIN", "ID", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/corngrain/ID_ip_US.png")
build_trends(trends_fris, "CORN_GRAIN", "OR", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/corngrain/OR_ip_US.png")
build_trends(trends_fris, "CORN_GRAIN", "WA", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/corngrain/WA_ip_US.png")
##### Corn Silage
build_trends(trends_fris, "CORN_SILAGE", "AZ", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/cornsilage/AZ_ip_US.png")
build_trends(trends_fris, "CORN_SILAGE", "CA", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/cornsilage/CA_ip_US.png")
build_trends(trends_fris, "CORN_SILAGE", "CO", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/cornsilage/CO_ip_US.png")
build_trends(trends_fris, "CORN_SILAGE", "ID", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/cornsilage/ID_ip_US.png")
build_trends(trends_fris, "CORN_SILAGE", "NM", EST_IP_LBS_AF,"Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/cornsilage/NM_ip_US.png")
build_trends(trends_fris, "CORN_SILAGE", "OR", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/cornsilage/OR_ip_US.png")
build_trends(trends_fris, "CORN_SILAGE", "UT", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/cornsilage/UT_ip_US.png")
build_trends(trends_fris, "CORN_SILAGE", "WA", EST_IP_LBS_AF, "Irrigation Productivity (pounds/acre foot)", "./viz/trends_ip/cornsilage/WA_ip_US.png")
####################################################################################################################
####### ESTIMATED AVERAGE YIELD (Metric)
####################################################################################################################
######## ALFALFA
build_trends(trends_fris, "ALFALFA", "AZ", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/alfalfa/AZ_yield.png")
build_trends(trends_fris, "ALFALFA", "CA", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/alfalfa/CA_yield.png")
build_trends(trends_fris, "ALFALFA", "CO", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/alfalfa/CO_yield.png")
build_trendsa(trends_fris, "ALFALFA", "ID", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/alfalfa/ID_yield.png") ## too many counties for palette, use alternate function
build_trends(trends_fris, "ALFALFA", "MT", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/alfalfa/MT_yield.png")
build_trends(trends_fris, "ALFALFA", "NV", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/alfalfa/NV_yield.png")
build_trends(trends_fris, "ALFALFA", "NM", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/alfalfa/NM_yield.png")
build_trends(trends_fris, "ALFALFA", "OR", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/alfalfa/OR_yield.png")
build_trendsa(trends_fris, "ALFALFA", "UT", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/alfalfa/UT_yield.png") ## too many counties for palette, use alternate function
build_trends(trends_fris, "ALFALFA", "WA", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/alfalfa/WA_yield.png")
build_trends(trends_fris, "ALFALFA", "WY", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/alfalfa/WY_yield.png")
######## HAY
build_trends(trends_fris, "OTHER_HAY", "AZ", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/hay/AZ_yield.png")
build_trends(trends_fris, "OTHER_HAY", "CA", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/hay/CA_yield.png")
build_trends(trends_fris, "OTHER_HAY", "CO", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/hay/CO_yield.png")
build_trends(trends_fris, "OTHER_HAY", "ID", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/hay/ID_yield.png")
build_trends(trends_fris, "OTHER_HAY", "MT", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/hay/MT_yield.png")
build_trends(trends_fris, "OTHER_HAY", "NV", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/hay/NV_yield.png")
build_trends(trends_fris, "OTHER_HAY", "OR", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/hay/OR_yield.png")
build_trends(trends_fris, "OTHER_HAY", "UT", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/hay/UT_yield.png")
build_trends(trends_fris, "OTHER_HAY", "WA", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/hay/WA_yield.png")
build_trends(trends_fris, "OTHER_HAY", "WY", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/hay/WY_yield.png")
##### WHEAT
build_trends(trends_fris, "WHEAT", "AZ", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/wheat/AZ_yield.png")
build_trends(trends_fris, "WHEAT", "CA", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/wheat/CA_yield.png")
build_trends(trends_fris, "WHEAT", "CO", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/wheat/CO_yield.png")
build_trends(trends_fris, "WHEAT", "ID", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/wheat/ID_yield.png")
build_trends(trends_fris, "WHEAT", "OR", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/wheat/OR_yield.png")
build_trends(trends_fris, "WHEAT", "UT", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/wheat/UT_yield.png")
build_trends(trends_fris, "WHEAT", "WA", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/wheat/WA_yield.png")
##### Corn Grain
build_trends(trends_fris, "CORN_GRAIN", "CA", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/corngrain/CA_yield.png")
build_trends(trends_fris, "CORN_GRAIN", "CO", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/corngrain/CO_yield.png")
build_trends(trends_fris, "CORN_GRAIN", "ID", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/corngrain/ID_yield.png")
build_trends(trends_fris, "CORN_GRAIN", "OR", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/corngrain/OR_yield.png")
build_trends(trends_fris, "CORN_GRAIN", "WA", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/corngrain/WA_yield.png")
##### Corn Silage
build_trends(trends_fris, "CORN_SILAGE", "AZ", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/cornsilage/AZ_yield.png")
build_trends(trends_fris, "CORN_SILAGE", "CA", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/cornsilage/CA_yield.png")
build_trends(trends_fris, "CORN_SILAGE", "CO", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/cornsilage/CO_yield.png")
build_trends(trends_fris, "CORN_SILAGE", "ID", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/cornsilage/ID_yield.png")
build_trends(trends_fris, "CORN_SILAGE", "NM", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/cornsilage/NM_yield.png")
build_trends(trends_fris, "CORN_SILAGE", "OR", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/cornsilage/OR_yield.png")
build_trends(trends_fris, "CORN_SILAGE", "UT", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/cornsilage/UT_yield.png")
build_trends(trends_fris, "CORN_SILAGE", "WA", EST_AVE_YIELD_KG, "Yield (kilograms/hectare)", "./viz/trends_yield/cornsilage/WA_yield.png")
####################################################################################################################
####### Estimated Average Yield (US)
####################################################################################################################
######## ALFALFA
build_trends(trends_fris, "ALFALFA", "AZ", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/alfalfa/AZ_yield_US.png")
build_trends(trends_fris, "ALFALFA", "CA", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/alfalfa/CA_yield_US.png")
build_trends(trends_fris, "ALFALFA", "CO", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/alfalfa/CO_yield_US.png")
build_trendsa(trends_fris, "ALFALFA", "ID", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/alfalfa/ID_yield_US.png") ## too many counties for palette, use alternate function
build_trends(trends_fris, "ALFALFA", "MT", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/alfalfa/MT_yield_US.png")
build_trends(trends_fris, "ALFALFA", "NV", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/alfalfa/NV_yield_US.png")
build_trends(trends_fris, "ALFALFA", "NM", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/alfalfa/NM_yield_US.png")
build_trends(trends_fris, "ALFALFA", "OR", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/alfalfa/OR_yield_US.png")
build_trendsa(trends_fris, "ALFALFA", "UT", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/alfalfa/UT_yield_US.png") ## too many counties for palette, use alternate function
build_trends(trends_fris, "ALFALFA", "WA", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/alfalfa/WA_yield_US.png")
build_trends(trends_fris, "ALFALFA", "WY", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/alfalfa/WY_yield_US.png")
######## HAY
build_trends(trends_fris, "OTHER_HAY", "AZ", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/hay/AZ_yield_US.png")
build_trends(trends_fris, "OTHER_HAY", "CA", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/hay/CA_yield_US.png")
build_trends(trends_fris, "OTHER_HAY", "CO", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/hay/CO_yield_US.png")
build_trends(trends_fris, "OTHER_HAY", "ID", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/hay/ID_yield_US.png")
build_trends(trends_fris, "OTHER_HAY", "MT", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/hay/MT_yield_US.png")
build_trends(trends_fris, "OTHER_HAY", "NV", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/hay/NV_yield_US.png")
build_trends(trends_fris, "OTHER_HAY", "OR", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/hay/OR_yield_US.png")
build_trends(trends_fris, "OTHER_HAY", "UT", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/hay/UT_yield_US.png")
build_trends(trends_fris, "OTHER_HAY", "WA", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/hay/WA_yield_US.png")
build_trends(trends_fris, "OTHER_HAY", "WY", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/hay/WY_yield_US.png")
##### WHEAT
build_trends(trends_fris, "WHEAT", "AZ", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/wheat/AZ_yield_US.png")
build_trends(trends_fris, "WHEAT", "CA", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/wheat/CA_yield_US.png")
build_trends(trends_fris, "WHEAT", "CO", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/wheat/CO_yield_US.png")
build_trends(trends_fris, "WHEAT", "ID", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/wheat/ID_yield_US.png")
build_trends(trends_fris, "WHEAT", "OR", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/wheat/OR_yield_US.png")
build_trends(trends_fris, "WHEAT", "UT", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/wheat/UT_yield_US.png")
build_trends(trends_fris, "WHEAT", "WA", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/wheat/WA_yield_US.png")
##### Corn Grain
build_trends(trends_fris, "CORN_GRAIN", "CA", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/corngrain/CA_yield_US.png")
build_trends(trends_fris, "CORN_GRAIN", "CO", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/corngrain/CO_yield_US.png")
build_trends(trends_fris, "CORN_GRAIN", "ID", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/corngrain/ID_yield_US.png")
build_trends(trends_fris, "CORN_GRAIN", "OR", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/corngrain/OR_yield_US.png")
build_trends(trends_fris, "CORN_GRAIN", "WA", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/corngrain/WA_yield_US.png")
##### Corn Silage
build_trends(trends_fris, "CORN_SILAGE", "AZ", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/cornsilage/AZ_yield_US.png")
build_trends(trends_fris, "CORN_SILAGE", "CA", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/cornsilage/CA_yield_US.png")
build_trends(trends_fris, "CORN_SILAGE", "CO", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/cornsilage/CO_yield_US.png")
build_trends(trends_fris, "CORN_SILAGE", "ID", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/cornsilage/ID_yield_US.png")
build_trends(trends_fris, "CORN_SILAGE", "NM", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/cornsilage/NM_yield_US.png")
build_trends(trends_fris, "CORN_SILAGE", "OR", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/cornsilage/OR_yield_US.png")
build_trends(trends_fris, "CORN_SILAGE", "UT", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/cornsilage/UT_yield_US.png")
build_trends(trends_fris, "CORN_SILAGE", "WA", EST_AVE_YIELD_LBS, "Yield (pounds/acre)", "./viz/trends_yield/cornsilage/WA_yield_US.png")
####################################################################################################################
####### ESTIMATED AVERAGE WATER USE (Metric)
####################################################################################################################
######## ALFALFA
build_trends(trends_fris, "ALFALFA", "AZ", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/alfalfa/AZ_wateruse.png")
build_trends(trends_fris, "ALFALFA", "CA", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/alfalfa/CA_wateruse.png")
build_trends(trends_fris, "ALFALFA", "CO", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/alfalfa/CO_wateruse.png")
build_trendsa(trends_fris, "ALFALFA", "ID", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/alfalfa/ID_wateruse.png") ## too many counties for palette, use alternate function
build_trends(trends_fris, "ALFALFA", "MT", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/alfalfa/MT_wateruse.png")
build_trends(trends_fris, "ALFALFA", "NV", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/alfalfa/NV_wateruse.png")
build_trends(trends_fris, "ALFALFA", "NM", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/alfalfa/NM_wateruse.png")
build_trends(trends_fris, "ALFALFA", "OR", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/alfalfa/OR_wateruse.png")
build_trendsa(trends_fris, "ALFALFA", "UT", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/alfalfa/UT_wateruse.png") ## too many counties for palette, use alternate function
build_trends(trends_fris, "ALFALFA", "WA", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/alfalfa/WA_wateruse.png")
build_trends(trends_fris, "ALFALFA", "WY", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/alfalfa/WY_wateruse.png")
######## HAY
build_trends(trends_fris, "OTHER_HAY", "AZ", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/hay/AZ_wateruse.png")
build_trends(trends_fris, "OTHER_HAY", "CA", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/hay/CA_wateruse.png")
build_trends(trends_fris, "OTHER_HAY", "CO", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/hay/CO_wateruse.png")
build_trends(trends_fris, "OTHER_HAY", "ID", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/hay/ID_wateruse.png")
build_trends(trends_fris, "OTHER_HAY", "MT", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/hay/MT_wateruse.png")
build_trends(trends_fris, "OTHER_HAY", "NV", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/hay/NV_wateruse.png")
build_trends(trends_fris, "OTHER_HAY", "OR", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/hay/OR_wateruse.png")
build_trends(trends_fris, "OTHER_HAY", "UT", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/hay/UT_wateruse.png")
build_trends(trends_fris, "OTHER_HAY", "WA", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/hay/WA_wateruse.png")
build_trends(trends_fris, "OTHER_HAY", "WY", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/hay/WY_wateruse.png")
##### WHEAT
build_trends(trends_fris, "WHEAT", "AZ", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/wheat/AZ_wateruse.png")
build_trends(trends_fris, "WHEAT", "CA", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/wheat/CA_wateruse.png")
build_trends(trends_fris, "WHEAT", "CO", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/wheat/CO_wateruse.png")
build_trends(trends_fris, "WHEAT", "ID", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/wheat/ID_wateruse.png")
build_trends(trends_fris, "WHEAT", "OR", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/wheat/OR_wateruse.png")
build_trends(trends_fris, "WHEAT", "UT", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/wheat/UT_wateruse.png")
build_trends(trends_fris, "WHEAT", "WA", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/wheat/WA_wateruse.png")
##### Corn Grain
build_trends(trends_fris, "CORN_GRAIN", "CA", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/corngrain/CA_wateruse.png")
build_trends(trends_fris, "CORN_GRAIN", "CO", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/corngrain/CO_wateruse.png")
build_trends(trends_fris, "CORN_GRAIN", "ID", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/corngrain/ID_wateruse.png")
build_trends(trends_fris, "CORN_GRAIN", "OR", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/corngrain/OR_wateruse.png")
build_trends(trends_fris, "CORN_GRAIN", "WA", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/corngrain/WA_wateruse.png")
##### Corn Silage
build_trends(trends_fris, "CORN_SILAGE", "AZ", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/cornsilage/AZ_wateruse.png")
build_trends(trends_fris, "CORN_SILAGE", "CA", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/cornsilage/CA_wateruse.png")
build_trends(trends_fris, "CORN_SILAGE", "CO", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/cornsilage/CO_wateruse.png")
build_trends(trends_fris, "CORN_SILAGE", "ID", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/cornsilage/ID_wateruse.png")
build_trends(trends_fris, "CORN_SILAGE", "NM", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/cornsilage/NM_wateruse.png")
build_trends(trends_fris, "CORN_SILAGE", "OR", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/cornsilage/OR_wateruse.png")
build_trends(trends_fris, "CORN_SILAGE", "UT", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/cornsilage/UT_wateruse.png")
build_trends(trends_fris, "CORN_SILAGE", "WA", EST_AVE_WU_M, "Water Application (cubic meters/hectare)", "./viz/trends_wateruse/cornsilage/WA_wateruse.png")