generated from edgi-govdata-archiving/Template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
State_template_2022.rmd
1402 lines (1129 loc) · 78.8 KB
/
State_template_2022.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: "Environmental Enforcement Watch"
header-includes:
- \usepackage{draftwatermark}
output:
html_paged:
number_sections: false
css: ["custom_current.css"]
params:
full_name: "Iowa"
state: "IA"
---
\SetWatermarkText{DRAFT}
```{r setup, include=FALSE}
library(reticulate)
library(RSQLite)
library(rlist)
library(tidyverse)
library(patchwork)
library(here)
library(ggplot2)
library(tidyr)
library(dplyr)
library(shiny)
library(extrafont)
library(viridis)
library(grid)
library(gridExtra)
library(kableExtra)
library(ggrepel)
library(stringr)
library(reshape)
loadfonts()
target_year <- '2021'
state <- params$state
full_name <- params$full_name
output_loc <- paste('Output/',state,"/",sep="")
dir.create(output_loc)
conn <- dbConnect( RSQLite::SQLite(), "leg_info.db")
senators = dbGetQuery( conn, "select * from legislators where cd_state=?",
params=c( state ))
dbDisconnect( conn )
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
```
```{r echo=FALSE, include=FALSE}
virtualenv_python('edgienv')
u <- import( 'Region' )
region <- u$Region(type='State', state=state, programs=c('CAA', 'CWA', 'RCRA'))
target_year_int <- strtoi( target_year )
violations <- region$get_events( 'violations', 'All', target_year_int )
CAAviolations <- region$get_events( 'violations', 'CAA', target_year_int )
CWAviolations <- region$get_events( 'violations', 'CWA', target_year_int )
RCRAviolations <- region$get_events( 'violations', 'RCRA', target_year_int )
USAinspectionsper1000_All <- region$get_per_1000( 'inspections', 'USA', target_year_int )
inspectionsper1000_state <- region$get_per_1000( 'inspections', 'State', target_year_int )
USAviolationsper1000_All <- region$get_per_1000( 'violations', 'USA', target_year_int )
violationsper1000_state <- region$get_per_1000( 'violations', 'State', target_year_int )
inflation <- region$get_inflation( target_year_int )
CAAenforcement_clean <- region$get_events( 'enforcements', 'CAA', target_year_int )
CWAenforcement_clean <- region$get_events( 'enforcements', 'CWA', target_year_int )
RCRAenforcement_clean <- region$get_events( 'enforcements', 'RCRA', target_year_int )
enforcement <- region$get_events( 'enforcements', 'All', target_year_int )
CWArecurring <- region$get_recurring_violations( 'CWA' )
inspections <- region$get_events( 'inspections', 'All', target_year_int )
CAAinspections <- region$get_events( 'inspections', 'CAA', target_year_int )
CWAinspections <- region$get_events( 'inspections', 'CWA', target_year_int )
RCRAinspections <- region$get_events( 'inspections', 'RCRA', target_year_int )
CAAbadactors <- region$get_non_compliants( 'CAA' )
CWAbadactors <- region$get_non_compliants( 'CWA' )
RCRAbadactors <- region$get_non_compliants( 'RCRA' )
ranked <- round(region$get_ranked())
ranked_t <- data.table::transpose(ranked)
ranked_t["Program"] <- c("CAA", "CAA", "CAA", "CWA", "CWA","CWA","RCRA", "RCRA","RCRA")
ranked_t["Metric"] <- c("Viol/Insp", "Violations", "Viol/Enf", "Viol/Insp", "Violations", "Viol/Enf", "Viol/Insp", "Violations", "Viol/Enf")
```
```{r readData, echo=FALSE}
names(USAinspectionsper1000_All)[1] <- "Program"
names(USAviolationsper1000_All)[1] <- "Program"
names(inflation)[2] <- "base"
#set up a theme default to reduce code block later
theme_meg <- function () {
theme_bw(base_family="Georgia") %+replace%
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),panel.border = element_blank(),
axis.line = element_line(colour = "black"), axis.title.x=element_text(face = "bold", size = 12),
axis.title.y=element_text(face = "bold", size = 10, angle=90), plot.title=element_text(face = "bold", size = 14, hjust =.5),
axis.text.x=element_text(face = "bold", size = 14), axis.text.y=element_text(face = "bold", size = 8))
}
sen1_name <- senators[1, "name"]
sen2_name <- senators[2, "name"]
sen1_since <- senators[1, "since_date"]
sen2_since <- senators[2, "since_date"]
map_src <- paste('State_maps/',state,'_map.png',sep='')
this_state <- params$state
```
<div class="title"><span style="padding-left: 150px">
Congressional Report Card
</span></div>
<hr style="height:3px;border-width:0; margin-left:15px; margin-right:15px;color: #b9b9b9;background-color: #b9b9b9; margin-top: 0em; margin-bottom: 0em">
##### `r full_name`; seats held by `r sen1_name` since `r sen1_since` and `r sen2_name` since `r sen2_since`
<div class="container">
<img src="`r map_src`" alt="Snow" style="width:100%;">
<div class="circle-map1">`r region$get_active_facilities('CAA')`</div>
<div class="circle-map2">`r region$get_active_facilities('CWA')`</div>
<div class="circle-map3">`r region$get_active_facilities('RCRA')`</div>
<div class="facility1">facilities</div>
<div class="facility2">facilities</div>
<div class="facility3">facilities</div>
<div class="rectangle">Operating Facilities</div>
<div class="circle-caa">CAA</div>
<div class="circle-cwa">CWA</div>
<div class="circle-rcra">RCRA</div>
<div class="bottom-left">Map shows `r full_name` with number of regulated facilities per program.</div>
</div>
<a href="https://www.environmentalenforcementwatch.org/"><img src="logosandimages/eew_logo.png" style="float: left; width: 9%; margin-left: 30%"></a>
<a href="https://envirodatagov.org/"><img src="logosandimages/edgi_logo.png" style="float: right; width: 15%; margin-right: 30%" ></a>
\pagebreak
<h4>Report Generated on `r format(Sys.time(), '%B %d, %Y')`<span style="padding-left:400px">Page 1</span></h4>
# Introduction
## Why Report Cards on compliance with and enforcement of Environmental Laws?
The Environmental Protection Agency (EPA) is charged by Congress to enforce laws that protect people from air pollution, water pollution and hazardous waste. **Without effective enforcement, these laws are meaningless**. Based on data from EPA’s Enforcement and Compliance History Online (ECHO) database this report card reviews violations, inspections and enforcement actions under three laws: Clean Air Act (CAA), Clean Water Act (CWA) and Resource Conservation and Recovery Act (RCRA) for this Congressional District or State since 2001. Report cards like this one are becoming available on the [EEW website](https://www.environmentalenforcementwatch.org) for all House Representatives and Senators. The [EEW website](https://www.environmentalenforcementwatch.org) also has a summary analysis of enforcement trends and data issues for all geographies covered by the House Energy and Commerce and Senate Environment and Public Works Committees. The report cards contain data from *both* state environmental agencies and the EPA. If the states are enforcing the above laws, it is because the EPA has delegated that authority to them. The EPA must ensure that states are doing their job. Congress must ensure that the EPA is doing its job. And the public must have accurate data from states and the EPA in order to understand if national environmental laws are being properly enforced. For the first time, EEW Congressional Report Cards give members of Congress and their constituents the chance to evaluate whether the EPA is fulfilling its mandate in their district. Congress can strengthen EPA enforcement by increasing its budget, passing more effective laws, requiring better data collection, and holding the EPA accountable when it fails to protect people.
## What is a "regulated facility"?
<a ><img src="logosandimages/facilities2.png" style="float: center; width: 70%; margin-left: 15%" ></a>
<br />
A regulated facility in this report is a facility that reports air or water emissions under the Clean Air Act or Clean Water Act, or a facility that generates, transports, or disposes of hazardous waste under the Resource Conservation and Recovery Act. Regulated facilities can be large-scale e.g. oil refineries, or small-scale e.g. dry cleaners.
\pagebreak
<hr style="height:3px;border-width:0;margin-left:15px; margin-right:15px;color: #C1E0D7;background-color: #C1E0D7; margin-top: 0em; margin-bottom: 0em">
<h4>Report Generated on `r format(Sys.time(), '%B %d, %Y')`<span style="padding-left:400px">Page 2</span></h4>
# Grading the District on Data from 2017 through 2021
<h3>This graph shows how this district compares by its percentile with other U.S. congressional districts on three metrics: number of violations, number of violations per inspection, and number of violations per enforcement action. These metrics are used on the data from each of the three EPA programs--the Clean Water Act (CWA), the Clean Air Act (CAA) and the Resource Conservation and Recovery Act (RCRA). The data used is for the past five years, 2017 through 2021.</h3>
<br />
```{r, fig.height = 5, fig.width = 8, fig.align = "center"}
grade <- function(score) {
return (case_when(score >= 40 ~ 'F',
score >= 30 ~ 'D',
score >= 20 ~ 'C',
score >= 10 ~ 'B',
TRUE ~ 'A'))
}
metric_colors <- c("darkblue", "#008080", "orange")
# ranked_t$order <- c("b","a","c","e","d","f","h","g","i")
ranked_t$order <- c("b","a","c","b","a","c","b","a","c")
state_rank_bar <- ggplot(ranked_t, aes(fill=order, y=V1, x=Program, alpha=Program))+
geom_bar(position="dodge", stat="identity")+
scale_fill_manual(values=metric_colors, labels = c("Violations/Facility","Violations/Inspections","Violations/Enforcements"))+
labs(y="Percentiles Among Districts\n", x="")+scale_alpha_manual(values=c(1,1,1), guide='none')+
geom_text(aes(label=V1, family="Georgia"), position = position_dodge(0.9), vjust = -0.1, size=5)+
ggtitle(paste("Ranking Among All States, 2017-2021"))+
scale_y_continuous(expand=c(0,0),limits=c(0,50))+
theme_meg()
```
```{r echo=FALSE, fig.height=3, out.width= "95%", out.extra='style="float:center; padding:0px"'}
state_rank_bar
```
<h3>As an example, a Violations ranking of `r ranked$CWA_Viol_Rank` for CWA means that this state has more violations per facility than `r ranked$CWA_Viol_Rank` of all states in the United States. From these rankings we can assign letter grades to states--the top 10, those states with more violations than 80% of all states, would get an F; the states scoring between 30 and 40 get a D; between 20 and 30 get a C; between 10 and 20 get a B; and the 10 with least violations per facility get an A. With that grading scheme, `r params$full_name` is given the following grades:</h3>
<ul>
<li><h3>CAA Violations per Facility - `r grade(ranked$CAA_Viol_Rank)`</h3></li>
<li><h3>CAA Violations per Inspection - `r grade(ranked$CAA_Insp_Rank)`</h3></li>
<li><h3>CAA Violations per Enforcement - `r grade(ranked$CAA_Enf_Rank)`</h3></li>
<li><h3>CWA Violations per Facility - `r grade(ranked$CWA_Viol_Rank)`</h3></li>
<li><h3>CWA Violations per Inspection - `r grade(ranked$CWA_Insp_Rank)`</h3></li>
<li><h3>CWA Violations per Enforcement - `r grade(ranked$CWA_Enf_Rank)`</h3></li>
<li><h3>RCRA Violations per Facility - `r grade(ranked$RCRA_Viol_Rank)`</h3></li>
<li><h3>RCRA Violations per Inspection - `r grade(ranked$RCRA_Insp_Rank)`</h3></li>
<li><h3>RCRA Violations per Enforcement - `r grade(ranked$RCRA_Enf_Rank)`</h3></li>
</ul>
<h3>Rationale for grading using these metrics:</h3>
<ul>
<li>More <strong>violations per active facility</strong> are worse.</li>
<li>More <strong>inspections</strong> mean more problems will be found, which is good. Dividing violations by inspections indicates the strength of the inspecting</li>
<li>More <strong>enforcements</strong> when violations are found disincentivizes violating. Dividing violations by enforcements indicates the willingness to call fouls.</li>
</ul>
*see data limitations page for metric calculations
\pagebreak
```{python echo=FALSE}
import warnings
warnings.filterwarnings("ignore")
from create_df import create_df
cwa_insp_years = create_df(region_type='State',data_type='inspections',
y_field='Count',program='CWA',states=[r.this_state,])
cwa_viol_years = create_df(region_type='State',data_type='violations',
y_field='Count',program='CWA',states=[r.this_state,])
cwa_enf_count_years = create_df(region_type='State',data_type='enforcements',
y_field='Count',program='CWA',states=[r.this_state,])
cwa_enf_count_years = cwa_enf_count_years.drop('Amount',1)
cwa_enf_dollar_years = create_df(region_type='State',data_type='enforcements',
y_field='Amount',program='CWA',states=[r.this_state,])
cwa_enf_dollar_years = cwa_enf_dollar_years.drop('Count',1)
cwa_enf_dollar_years['USA'] = cwa_enf_dollar_years['USA']/1000.
cwa_enf_dollar_years[r.this_state] = cwa_enf_dollar_years[r.this_state]/1000.
```
```{r echo=FALSE, include=FALSE}
cwa_insp_years <- reshape::melt(py$cwa_insp_years, id=c("Year"))
cwa_viol_years <- reshape::melt(py$cwa_viol_years, id=c("Year"))
cwa_enf_count_years <- reshape::melt(py$cwa_enf_count_years, id=c("Year"))
cwa_enf_dollar_years <- reshape::melt(py$cwa_enf_dollar_years, id=c("Year"))
```
```{r echo=FALSE, include=FALSE}
# Color selection
region_colors <- c("darkblue", "#008080", "orange", "#46B8DA")
graph1 <- ggplot(cwa_insp_years, aes(x = Year, y = value, color = variable)) +
geom_line() +
scale_color_manual(values = region_colors) +
guides(color = guide_legend(title = "Regions")) +
labs(y="# Inspections", x="Year", title="CWA - Inspections Per Facility")
graph2 <- ggplot(cwa_viol_years, aes(x = Year, y = value, color = variable)) +
geom_line() +
scale_color_manual(values = region_colors) +
guides(color = guide_legend(title = "Regions")) +
labs(y="# Violations", x="Year", title="CWA - Violations Per Facility")
graph3 <- ggplot(cwa_enf_count_years, aes(x = Year, y = value, color = variable)) +
geom_line() +
scale_color_manual(values = region_colors) +
guides(color = guide_legend(title = "Regions")) +
labs(y="# Enforcements", x="Year", title="CWA - Enforcement Actions Per Facility")
graph4 <- ggplot(cwa_enf_dollar_years, aes(x = Year, y = value, color = variable)) +
geom_line() +
scale_color_manual(values = region_colors) +
guides(color = guide_legend(title = "Regions")) +
labs(y="Fines ($1000)", x="Year", title="CWA - Enforcement Fines Per Facility")
```
```{r echo=FALSE}
which_president <- function(which_year) {
case_when(
which_year < 2009 ~ "Bush",
which_year < 2017 & which_year > 2008 ~ "Obama",
which_year < 2021 & which_year > 2016 ~ "Trump",
which_year > 2020 ~ "Biden"
)
}
##getting %difference CWA violations
CWAviolations <- CWAviolations %>%
mutate(President = which_president(Year))
vCWAchange <- data.frame("BushObamaAverage" =mean(CWAviolations[1:16,2]),
"Trump Average" =mean(CWAviolations[17:20,2])) # SH
vCWAchange$PercentDifference <- as.numeric(100*(vCWAchange[1,2]-vCWAchange[1,1])/
vCWAchange[1,1])
vCWAchange$PercentDifference <-round(vCWAchange$PercentDifference,0)
vCWAchange$Extra <- ifelse((vCWAchange$PercentDifference>=100)|(vCWAchange$PercentDifference<=-100), "much", "")
vCWAchange$Change <- ifelse(vCWAchange$PercentDifference<0, "better", "worse")
vCWAchange$Positive <- abs(vCWAchange$PercentDifference)
vCWAchange$Value <- ifelse(vCWAchange$PercentDifference>=0, "increase", "decrease")
#enforcement % difference
enforcement$Amount <- round(enforcement$Amount,2)
#add presidental years
enforcement <- enforcement %>%
mutate(President = which_president(Year))
actionchange <- data.frame("BushObamaAverage" =mean(enforcement[1:16,3]),
"Trump Average" =mean(enforcement[17:19,3]))
actionchange$PercentDifference <- as.numeric(100*(actionchange[1,2]-actionchange[1,1])/
actionchange[1,1])
actionchange$PercentDifference <-round(actionchange$PercentDifference,0)
actionchange$Extra <- ifelse((actionchange$PercentDifference>=100)|(actionchange$PercentDifference<=-100), "much", "")
actionchange$Change <- ifelse(actionchange$PercentDifference<0, "worse", "better")
actionchange$Positive <- abs(actionchange$PercentDifference)
actionchange$Value <- ifelse(actionchange$PercentDifference>=0, "increase", "decrease")
```
<br />
<hr style="height:3px;border-width:0;margin-left:15px; margin-right:15px;color: #C1E0D7;background-color: #C1E0D7; margin-top: 0em; margin-bottom: 0em">
<h4>Report Generated on `r format(Sys.time(), '%B %d, %Y')`<span style="padding-left:400px">Page 3</span></h4>
# Clean Water Act - Inspections, Violations, Enforcements Since 2000
<h3>These graphs show the changes in numbers of inspections, violations and enforcement actions
per facility for the U.S., the state of `r params$state`,
under the Clean Water Act (CWA)*. </h3>
*(The current number of active
facilities is used for the calculations for all graphs, as the historical data for facility counts
was not available. The graphs therefore give trends rather than faithful statistics.)
<br />
```{r, fig.height = 5, fig.width = 8, fig.align = "center"}
(graph1 | graph2) / (graph3 | graph4)
```
<h3>Clean Water Act Violations*: <span style="color:#569b5e">Violations during the four Trump administration years were `r vCWAchange[1,4]` `r vCWAchange[1,5]`</span> than the average over the previous 16 years, representing a <span style="color:#569b5e">`r vCWAchange[1,6]`% `r vCWAchange[1,7]`</span> in violations</h3>
<br />
<h3>Enforcement Actions under Clean Air Act, Clean Water Act, and the Resource Conservation and Recovery Act*: <span style="color:#569b5e">`r actionchange[1,4]` `r actionchange[1,5]`</span> than the average over the previous 16 years, representing a <span style="color:#569b5e">`r actionchange[1,6]`% `r actionchange[1,7]`</span> in enforcement actions</h3>
<p>When comparing the graphs, note that the vertical axes may have considerably different scales.</p>
<br />
*see data limitations page for metric calculations
\pagebreak
<hr style="height:3px;border-width:0;color: #C1E0D7;background-color: #C1E0D7; margin-top: 2em">
<h4>Report Generated on `r format(Sys.time(), '%B %d, %Y')`<span style="padding-left:400px">Page 3</span></h4>
```{r echo=FALSE}
#CWA
##first let's fix up the data
#ok so We'll put the % in the title for the state, and try to figure out the same for the state
CWArecurring <- CWArecurring %>%
select(State,Facilities, Percent)
names(CWArecurring)[1] <- "Region"
CWArecurring[3] <-round(CWArecurring[3],0)
```
```{r echo=FALSE}
which_president <- function(which_year) {
case_when(
which_year < 2009 ~ "Bush",
which_year < 2017 & which_year > 2008 ~ "Obama",
which_year < 2021 & which_year > 2016 ~ "Trump",
which_year > 2020 ~ "Biden"
)
}
##getting %difference CWA violations
CWAviolations <- CWAviolations %>%
mutate(President = which_president(Year))
vCWAchange <- data.frame("BushObamaAverage" =mean(CWAviolations[1:16,2]),
"Trump Average" =mean(CWAviolations[17:20,2])) # SH
vCWAchange$PercentDifference <- as.numeric(100*(vCWAchange[1,2]-vCWAchange[1,1])/
vCWAchange[1,1])
vCWAchange$PercentDifference <-round(vCWAchange$PercentDifference,0)
vCWAchange$Extra <- ifelse((vCWAchange$PercentDifference>=100)|(vCWAchange$PercentDifference<=-100), "much", "")
vCWAchange$Change <- ifelse(vCWAchange$PercentDifference<0, "better", "worse")
vCWAchange$Positive <- abs(vCWAchange$PercentDifference)
vCWAchange$Value <- ifelse(vCWAchange$PercentDifference>=0, "increase", "decrease")
#enforcement % difference
enforcement$Amount <- round(enforcement$Amount,2)
#add presidental years
enforcement <- enforcement %>%
mutate(President = which_president(Year))
actionchange <- data.frame("BushObamaAverage" =mean(enforcement[1:16,3]),
"Trump Average" =mean(enforcement[17:19,3]))
actionchange$PercentDifference <- as.numeric(100*(actionchange[1,2]-actionchange[1,1])/
actionchange[1,1])
actionchange$PercentDifference <-round(actionchange$PercentDifference,0)
actionchange$Extra <- ifelse((actionchange$PercentDifference>=100)|(actionchange$PercentDifference<=-100), "much", "")
actionchange$Change <- ifelse(actionchange$PercentDifference<0, "worse", "better")
actionchange$Positive <- abs(actionchange$PercentDifference)
actionchange$Value <- ifelse(actionchange$PercentDifference>=0, "increase", "decrease")
```
```{r echo=FALSE}
##getting %difference effluent violations
##So, we're going to do the first 3 years of Obama and Trump so average
#[9:11,2] Obama
# [17:19,2] Trump
effluentviolations <- CWAviolations
effluentchange <- data.frame("Obama Average" =mean(effluentviolations[9:12,2]),
"Trump Average" =mean(effluentviolations[17:20,2]))
effluentchange$PercentDifference <- as.numeric(100*(effluentchange[1,2]-effluentchange[1,1])/
effluentchange[1,1])
effluentchange[,1:3] <-round(effluentchange[,1:3],2)
president_colors <- c("#450d54", "#22908d", "#e56d13", "#0EAD5D")
#then simple plot
effluentgraph <- ggplot(effluentviolations, mapping=aes(x=factor(Year),
y=Count, fill=President, group=1))+
geom_bar(stat="identity", alpha=.6)+
scale_fill_manual(values=president_colors,breaks=c('Bush', 'Obama', 'Trump', 'Biden'), guide=guide_legend(breaks=c("Bush","Obama","Trump","Biden")))+
labs(y=" # Violations", x="Year", title="Clean Water Act Violations\n", subtitle ="Mostly complete data")+
scale_y_continuous(expand=c(0,0), limits=c(0,max(effluentviolations$Count+(.2*max(effluentviolations$Count)))))+
scale_x_discrete(breaks=c(2004,2008,2012,2016,2020))+
theme_meg()+
theme(axis.text.x=element_text(size=9),
axis.title.x = element_blank(), plot.subtitle = element_text(hjust=.5, size=10, color="darkgreen"),
plot.title =
element_text(lineheight = .1, size=10))
##Inspections % change and graph
##So, we're going to do the first 3 years of Obama and Trump so average
#[9:11,2] Obama
# [17:19,2] Trump
inspectionchange <- data.frame("Obama Average" =mean(inspections[9:12,2]),
"Trump Average" =mean(inspections[17:20,2]))
inspectionchange$PercentDifference <- as.numeric(100*(inspectionchange[1,2]-inspectionchange[1,1])/
inspectionchange[1,1])
inspectionchange[,1:3] <-round(inspectionchange[,1:3],0)
#syntax for bullet points
inspectionchange$Change <- ifelse(inspectionchange$PercentDifference>=0, "increase", "decrease")
inspectionchange$Positive <- abs(inspectionchange$PercentDifference)
#then simple plot
#first add in the Presidential Years
inspections$President <- as.character("Bush")
inspections[9:16,3] <- as.character("Obama")
inspections[17:20,3] <- as.character("Trump")
inspectiongraph <- ggplot(inspections, mapping=aes(x=factor(Year),
y=Count, fill=President, group=1))+
geom_bar(stat="identity", show.legend = FALSE, alpha=.6)+
scale_fill_manual(values=president_colors, breaks=c('Bush', 'Obama', 'Trump', 'Biden'))+
labs(y="Inspections", x="Year", title="Facility Inspections-CAA,CWA,RCRA\n", subtitle = "Potentially incomplete data")+
scale_y_continuous(expand=c(0,0), limits=c(0,max(inspections$Count+(.2*max(inspections$Count)))))+
scale_x_discrete(breaks=c(2004,2008,2012,2016,2020))+
theme_meg()+
theme(axis.text.x=element_text(size=9),
axis.title.x = element_blank(), plot.subtitle = element_text(size = 10, color = "dark gray", hjust=.5), plot.title =
element_text(lineheight = .1, size=10))
#enforcement
enforcement$Amount <- round(enforcement$Amount,0)
enforcementchange <- data.frame("Obama Average Count" =mean(enforcement[9:12,3]),
"Trump Average Count" =mean(enforcement[17:20,3]),
"Obama Average Fine" =mean(enforcement[9:12,2]),
"Trump Average Fine" =mean(enforcement[17:20,2]))
enforcementchange$PercentDifferenceCount <- as.numeric(100*(enforcementchange[1,2]-enforcementchange[1,1])/
enforcementchange[1,1])
enforcementchange$PercentDifferenceFine <- as.numeric(100*(enforcementchange[1,4]-enforcementchange[1,3])/
enforcementchange[1,3])
enforcementchange[,1:6] <-round(enforcementchange[,1:6],0)
#syntax for bullet points
enforcementchange$CountChange <- ifelse(enforcementchange$PercentDifferenceCount>=0, "increase", "decrease")
enforcementchange$PositiveCount <- abs(enforcementchange$PercentDifferenceCount)
enforcementchange$FineChange <- ifelse(enforcementchange$PercentDifferenceFine>=0, "increase", "decrease")
enforcementchange$PositiveFine <- abs(enforcementchange$PercentDifferenceFine)
#adjust for inflation
enforcement <- cbind(enforcement, inflation)
enforcement$inflationadjust <- as.numeric(enforcement$Amount*enforcement$base)
##make a new amount column /1000
enforcement$Amountinthousands <- ((enforcement$inflationadjust)/1000)
enforcement$Amountinthousands <-round(enforcement$Amountinthousands,2)
#add presidental years
enforcement$President <- as.character("Bush")
enforcement[9:16,4] <- as.character("Obama")
enforcement[17:20,4] <- as.character("Trump")
#plot change in enforcement
enforcementactiongraph <- ggplot(enforcement, mapping=aes(x=factor(Year),y=Count, fill=President, group=1))+
geom_bar(stat="identity", show.legend = FALSE, alpha=.6)+
scale_fill_manual(values=president_colors,breaks=c('Bush', 'Obama', 'Trump', 'Biden'), guide=guide_legend(breaks=c("Bush","Obama","Trump","Biden")))+
labs(y="# Actions", x="Year", title="Enforcement Actions-CAA,CWA,RCRA\n", subtitle = "Potentially incomplete data")+
scale_y_continuous(expand=c(0,0), limits=c(0,max(effluentviolations$Count+(.2*max(effluentviolations$Count)))))+
scale_x_discrete(breaks=c(2004,2008,2012,2016,2020))+
geom_text(aes(label=Count, family="Georgia", fontface="bold"), position = position_dodge(0.9), vjust = -0.1, size=2)+
theme_meg()+
theme(axis.text.x=element_text(size=9),
axis.title.x = element_blank(), plot.subtitle = element_text(hjust=.5, size=9), plot.title =
element_text(lineheight = .1, size=10))
enforcementfinegraph <- enforcement %>% ggplot()+
geom_bar(aes(x=factor(Year),y=Amountinthousands , fill=President, group=1),stat="identity", show.legend=FALSE, alpha=.6)+
scale_fill_manual(values=president_colors,breaks=c('Bush', 'Obama', 'Trump', 'Biden'), guide=guide_legend(breaks=c("Bush","Obama","Trump","Biden")))+
labs(y="Fines ($1000s)", x="Year", caption="Values adjusted for inflation. Note, the y-axis reports values in 1000's. A value of $2000\nrepresents $2,000,000 (2 million dollars).", title="Enforcement Fines-CAA,CWA,RCRA\n", subtitle="Potentially incomplete data")+
scale_y_continuous(expand=c(0,0), limits=c(0,max(enforcement$Amountinthousands+(.2*max(enforcement$Amountinthousands)))))+
scale_x_discrete(breaks=c(2004,2008,2012,2016,2020))+
theme_meg()+
theme(axis.text.x=element_text(size=9),
axis.title.x = element_blank(), plot.subtitle = element_text(hjust=.5, size=9), plot.caption = element_text(size=10), plot.title =
element_text(lineheight = .1, size=10))
```
# Highlights for `r full_name`
* <h3>Comparing the first 3 years of the Obama administration to the first 3 years of the Trump administration, there has been a <span style="color:#569b5e">`r inspectionchange[1,5]`% `r inspectionchange[1,4]` in inspections, `r enforcementchange[1,10]`% `r enforcementchange[1,9]` in fines</span>, and a <span style="color:#569b5e">`r enforcementchange[1,8]`% `r enforcementchange[1,7]` in enforcement actions.</span></h3>
<br />
* <h3>Under the Clean Water Act, the law whose regulation is best documented by available EPA data, <span style="color:#569b5e">`r CWArecurring[1,2]` facilities, representing `r CWArecurring[1,3]`% of all regulated facilities in `r state`,</span> were in violation for <span style="color:#569b5e">at least 9 months of the last 3 years.</span></h3>
```{r echo=FALSE, fig.height=6, out.width= "95%", out.extra='style="float:center; padding:0px"'}
effluentgraph/inspectiongraph/enforcementactiongraph/enforcementfinegraph
# effluentgraph
```
The reliability of data in figures throughout this report is indicated by the figure subtitle and degree of transparency. See the data limitations page (Page 10) to view the transparency-coding table and access state and congressional district data [here](https://colab.research.google.com/github/edgi-govdata-archiving/ECHO-Cross-Program/blob/master/AllPrograms.ipynb).
\pagebreak
<hr style="height:3px;border-width:0;color: #C1E0D7;background-color: #C1E0D7; margin-top: 2em">
<h4>Report Generated on `r format(Sys.time(), '%B %d, %Y')`<span style="padding-left:400px">Page 4</span></h4>
# This State in Comparison
```{r, fig.height = 6, fig.width = 8, fig.align = "left"}
#comparing inspections
#let's combine the inspections data at national, state, CD level
names(USAinspectionsper1000_All)[2] <- "Inspectionsper1000"
USAinspectionsper1000_All$Region <- as.factor("National")
names(inspectionsper1000_state)[2] <- "Inspectionsper1000"
inspectionsper1000_state$Region <- as.factor("State")
inspectionsper1000 <- rbind(USAinspectionsper1000_All, inspectionsper1000_state)
inspectionsper1000$Inspectionsper1000 <- as.numeric(inspectionsper1000$Inspectionsper1000)
inspectionsper1000[2] <-round(inspectionsper1000[2],0)
#Now let's visualize this
inspect1000bar <- ggplot(inspectionsper1000, aes(fill=Region, y=Inspectionsper1000, x=Program, alpha=Program))+
geom_bar(position="dodge", stat="identity")+
scale_fill_manual(values=c("#333333", "#d43a69"))+
labs(y="Inspections per 1000 Facilities\n", x="")+
scale_alpha_manual(values=c(.6,1,.6), guide='none')+
geom_text(aes(label=Inspectionsper1000, family="Georgia"), position = position_dodge(0.9), vjust = -0.1, size=4)+
ggtitle(paste("Inspections per 1000 Facilities in",target_year," "))+
scale_y_continuous(expand=c(0,0),limits=c(0,1200))+geom_hline(yintercept=1000, linetype="dashed", color="black")+geom_text(aes(label="Average of 1 inspection per facility",family="Georgia"),x=2,y=1050,color="black",size=4)+
theme_meg()
#comparing violations
#let's combine the violations data at national, state, CD level
names(USAviolationsper1000_All)[2] <- "violationsper1000"
USAviolationsper1000_All$Region <- as.factor("National")
names(violationsper1000_state)[2] <- "violationsper1000"
violationsper1000_state$Region <- as.factor("State")
violationsper1000 <- rbind(USAviolationsper1000_All, violationsper1000_state)
violationsper1000$violationsper1000 <- as.numeric(violationsper1000$violationsper1000)
violationsper1000[2] <-round(violationsper1000[2],0)
#Now let's visualize this
violations1000bar <- ggplot(violationsper1000, aes(fill=Region, y=violationsper1000, x=Program, alpha=Program))+
geom_bar(position="dodge", stat="identity", show.legend=FALSE)+
scale_fill_manual(values=c("#333333", "#d43a69"))+
scale_alpha_manual(values=c(.3,1,.3), guide='none')+
labs(y="Violations per 1000 Facilities", x="")+
geom_text(aes(label=violationsper1000, family="Georgia"), position = position_dodge(0.9), vjust = -0.1, size=4)+
ggtitle(paste("Violations per 1000 Facilities in",target_year," "))+
scale_y_continuous(expand=c(0,0),limits=c(0,max(violationsper1000$violationsper1000+(.2*max(violationsper1000$violationsper1000)))))+
theme_meg()+
theme(legend.position = c(0.8, 0.5))
inspect1000bar / violations1000bar
knitr::opts_chunk$set(fig.width = 10,fig.height = 6)
```
<br />
These two charts show how inspections and violations in this state compare to the national average per 1000 facilities in `r target_year`. We use data from `r target_year` as it was the most recent full year and the ECHO database only reports *currently* active facilities. To enable comparison across locations with a differing number of active facilities, we standardize the comparison to a value per 1000 facilities, proportionally adjusting the data if there are more or less than 1000 facilities in a district or state.
For access to the Jupyter Notebooks which pull data from ECHO at the state and congressional district level, click [here](https://colab.research.google.com/github/edgi-govdata-archiving/ECHO-Cross-Program/blob/master/AllPrograms.ipynb). For national data, click [here](https://colab.research.google.com/github/edgi-govdata-archiving/ECHO-Cross-Program/blob/master/ECHO_National.ipynb).
The reliability of data in figures throughout this report is indicated by the figure subtitle and degree of transparency. Figure transparency illustrates data reliability: the more transparent, the more uncertain the data. See the data limitations page (Page 10) to view the transparency-coding table
\pagebreak
<hr style="height:3px;border-width:0;color: #C1E0D7;background-color: #C1E0D7; margin-top: 2em">
<h4>Report Generated on `r format(Sys.time(), '%B %d, %Y')`<span style="padding-left:400px">Page 5</span></h4>
<h1><span style="margin-bottom:0px; padding-bottom:0px">Recent Non-Compliance in this State</span></h1>
<font size="2">These figures show the ten facilities in this state with the worst history of environmental compliance based on their number of noncompliant quarters in the past 3 years (not necessarily consecutive).</font>
```{r echo=FALSE, out.extra='style="float: left; width: 50%; height: 30%; margin-right: 5%"'}
#call in data and clean up
nrows_df <- nrow( CAAbadactors )
make_extras_string <- function(badactors) {
extras_string = ""
if (nrows_df > 10) {
last_fac_count = badactors[10,]$noncomp_count
extras_count = 0
for (i in 10:nrows_df) {
if (badactors[i,]$noncomp_count < last_fac_count) {
break
}
extras_count <- extras_count + 1
}
if (extras_count > 0) {
noun <- "facilities"
if (extras_count == 1) noun = "facility"
extras_string <- sprintf("%d additional %s with %d quarters in violation",
extras_count, noun, last_fac_count);
}
}
}
extras_string <- make_extras_string(CAAbadactors)
if ( nrows_df > 0 ) {
CAAbadactors <- CAAbadactors[-c(11:1000),] # SH
CAAbadactors$Facility <- CAAbadactors$fac_name # SH
CAAbadactors$Facility <- strtrim(CAAbadactors$Facility, 30)
bar_width <- 0.8
if ( nrows_df < 4 ) {
bar_width <- 0.2
}
#Let's try the CAA plot
if ( nrows_df == 1 ) {
CAAfacilities <- CAAbadactors %>%
mutate(Facility = fct_reorder(Facility, noncomp_count)) %>%
ggplot(aes(x=Facility, y=noncomp_count))+
geom_col(width = 0.1)+
scale_fill_viridis(discrete = TRUE, option="B")+
labs(y="Quarters in Violation", x="", title="CAA Violators")+
scale_y_continuous(expand=c(0,0), breaks=c(0,3,6,9,12), limits=c(0,13))+
# scale_x_discrete(expand=c(0,0))+
theme_meg()+
theme(axis.text.y=element_text(size=14, face = "bold", color="black"), axis.title.x = element_text(size=14), axis.text.x=element_text(size=14,face = "bold"), plot.title=element_text(size=16))+
coord_flip()
} else {
CAAfacilities <- CAAbadactors %>%
mutate(Facility = fct_reorder(Facility, noncomp_count)) %>%
ggplot( mapping=aes(x=Facility, y=noncomp_count, fill=Facility, group=1))+
geom_bar(stat="identity", show.legend = FALSE, width=bar_width)+
scale_fill_viridis(discrete = TRUE, option="B")+
labs(y="Quarters in Violation", x="", title="CAA Violators")+
scale_y_continuous(expand=c(0,0), breaks=c(0,3,6,9,12), limits=c(0,13))+
scale_x_discrete(expand=c(0,0))+
theme_meg()+
theme(axis.text.y=element_text(size=14, face = "bold", color="black"), axis.title.x = element_text(size=14), axis.text.x=element_text(size=14,face = "bold"), plot.title=element_text(size=16))+
coord_flip()
}
CAAfacilities
}
```
<br />
<p style="text-align: right;"><font size="3">**ECHO reports for facilities:**</font></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CAAbadactors[1,7]) `](`r na.omit(CAAbadactors[1,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CAAbadactors[2,7]) `](`r na.omit(CAAbadactors[2,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CAAbadactors[3,7]) `](`r na.omit(CAAbadactors[3,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CAAbadactors[4,7]) `](`r na.omit(CAAbadactors[4,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CAAbadactors[5,7]) `](`r na.omit(CAAbadactors[5,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CAAbadactors[6,7]) `](`r na.omit(CAAbadactors[6,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CAAbadactors[7,7]) `](`r na.omit(CAAbadactors[7,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CAAbadactors[8,7]) `](`r na.omit(CAAbadactors[8,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CAAbadactors[9,7]) `](`r na.omit(CAAbadactors[9,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CAAbadactors[10,7]) `](`r na.omit(CAAbadactors[10,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">`r extras_string `</font>
<br />
<br />
```{r echo=FALSE, out.extra='style="float: left; width: 50%; height: 30%; margin-right: 5%; margin-top:1.5%"'}
#call in data and clean up
nrows_df <- nrow( RCRAbadactors )
extras_string <- make_extras_string(RCRAbadactors)
if ( nrows_df > 0 ) {
RCRAbadactors <- RCRAbadactors[-c(11:1000),] # SH -
RCRAbadactors$Facility <- RCRAbadactors$fac_name # SH -
RCRAbadactors$Facility <- strtrim(RCRAbadactors$Facility, 30)
bar_width <- 0.8
if ( nrows_df < 4 ) {
bar_width <- 0.2
}
#Let's try the RCRA plot
if ( nrows_df == 1 ) {
RCRAfacilities <- RCRAbadactors %>%
mutate(Facility = fct_reorder(Facility, noncomp_count)) %>%
ggplot(aes(x=Facility, y=noncomp_count))+
geom_col(width = 0.1)+
scale_fill_viridis(discrete = TRUE, option="B")+
labs(y="Quarters in Violation", x="", title="RCRA Violators")+
scale_y_continuous(expand=c(0,0), breaks=c(0,3,6,9,12), limits=c(0,13))+
# scale_x_discrete(expand=c(0,0))+
theme_meg()+
theme(axis.text.y=element_text(size=14, face = "bold", color="black"), axis.title.x = element_text(size=14), axis.text.x=element_text(size=14,face = "bold"), plot.title=element_text(size=16))+
coord_flip()
} else {
RCRAfacilities <- RCRAbadactors %>%
mutate(Facility = fct_reorder(Facility, noncomp_count)) %>%
ggplot( mapping=aes(x=Facility, y=noncomp_count, fill=Facility, group=1))+
geom_bar(stat="identity", show.legend = FALSE, width=bar_width)+
scale_fill_viridis(discrete = TRUE, option="B")+
labs(y="Quarters in Violation", x="", title="RCRA Violators")+
scale_y_continuous(expand=c(0,0), breaks=c(0,3,6,9,12), limits=c(0,13))+
scale_x_discrete(expand=c(0,0))+
theme_meg()+
theme(axis.text.y=element_text(size=14, face = "bold", color="black"), axis.title.x = element_text(size=14), axis.text.x=element_text(size=14,face = "bold"), plot.title=element_text(size=16))+
coord_flip()
}
RCRAfacilities
}
```
<p style="text-align: right;"><font size="3">**ECHO reports for facilities:**</font></p>
<p style="text-align: right;"><font size="2">[`r na.omit(RCRAbadactors[1,7]) `](`r na.omit(RCRAbadactors[1,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(RCRAbadactors[2,7]) `](`r na.omit(RCRAbadactors[2,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(RCRAbadactors[3,7]) `](`r na.omit(RCRAbadactors[3,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(RCRAbadactors[4,7]) `](`r na.omit(RCRAbadactors[4,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(RCRAbadactors[5,7]) `](`r na.omit(RCRAbadactors[5,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(RCRAbadactors[6,7]) `](`r na.omit(RCRAbadactors[6,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(RCRAbadactors[7,7]) `](`r na.omit(RCRAbadactors[7,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(RCRAbadactors[8,7]) `](`r na.omit(RCRAbadactors[8,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(RCRAbadactors[9,7]) `](`r na.omit(RCRAbadactors[9,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(RCRAbadactors[10,7]) `](`r na.omit(RCRAbadactors[10,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">`r extras_string `</font><br /></p>
<br />
<br />
```{r echo=FALSE, out.extra='style="float: left; width: 50%; height: 30%; margin-right: 5%; margin-top:1.5%"'}
#call in data and clean up
nrows_df <- nrow( CWAbadactors )
extras_string <- make_extras_string(CWAbadactors)
if ( nrows_df > 0 ) {
CWAbadactors <- CWAbadactors[-c(11:1000),] # SH -
CWAbadactors$Facility <- CWAbadactors$fac_name # SH -
CWAbadactors$Facility <- strtrim(CWAbadactors$Facility, 30)
bar_width <- 0.8
if ( nrows_df < 4 ) {
bar_width <- 0.2
}
#Let's try the CWA plot
if ( nrows_df == 1 ) {
CWAfacilities <- CWAbadactors %>%
mutate(Facility = fct_reorder(Facility, noncomp_count)) %>%
ggplot(aes(x=Facility, y=noncomp_count))+
geom_col(width = 0.1)+
scale_fill_viridis(discrete = TRUE, option="B")+
labs(y="Quarters in Violation", x="", title="CWA Violators")+
scale_y_continuous(expand=c(0,0), breaks=c(0,3,6,9,13), limits=c(0,14))+
# scale_x_discrete(expand=c(0,0))+
theme_meg()+
theme(axis.text.y=element_text(size=14, face = "bold", color="black"), axis.title.x = element_text(size=14), axis.text.x=element_text(size=14,face = "bold"), plot.title=element_text(size=16))+
coord_flip()
} else {
CWAfacilities <- CWAbadactors %>%
mutate(Facility = fct_reorder(Facility, noncomp_count)) %>%
ggplot( mapping=aes(x=Facility, y=noncomp_count, fill=Facility, group=1))+
geom_bar(stat="identity", show.legend = FALSE, width=bar_width)+
scale_fill_viridis(discrete = TRUE, option="B")+
labs(y="Quarters in Violation", x="", title="CWA Violators")+
scale_y_continuous(expand=c(0,0), breaks=c(0,3,6,9,13), limits=c(0,14))+
scale_x_discrete(expand=c(0,0))+
theme_meg()+
theme(axis.text.y=element_text(size=14, face = "bold", color="black"), axis.title.x = element_text(size=14), axis.text.x=element_text(size=14,face = "bold"), plot.title=element_text(size=16))+
coord_flip()
}
CWAfacilities
}
```
<p style="text-align: right;"><font size="3">**ECHO reports for facilities:**</font></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CWAbadactors[1,7]) `](`r na.omit(CWAbadactors[1,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CWAbadactors[2,7]) `](`r na.omit(CWAbadactors[2,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CWAbadactors[3,7]) `](`r na.omit(CWAbadactors[3,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CWAbadactors[4,7]) `](`r na.omit(CWAbadactors[4,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CWAbadactors[5,7]) `](`r na.omit(CWAbadactors[5,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CWAbadactors[6,7]) `](`r na.omit(CWAbadactors[6,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CWAbadactors[7,7]) `](`r na.omit(CWAbadactors[7,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CWAbadactors[8,7]) `](`r na.omit(CWAbadactors[8,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CWAbadactors[9,7]) `](`r na.omit(CWAbadactors[9,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">[`r na.omit(CWAbadactors[10,7]) `](`r na.omit(CWAbadactors[10,4]) `)</font><br /></p>
<p style="text-align: right;"><font size="2">`r extras_string `</font><br /></p>
\pagebreak
<hr style="height:3px;border-width:0;color: #C1E0D7;background-color: #C1E0D7; margin-top: 2em">
<h4>Report Generated on `r format(Sys.time(), '%B %d, %Y')`<span style="padding-left:400px">Page 6</span></h4>
# Clean Air Act
<div class="text-box-info">
The [Clean Air Act (CAA)](https://www.epa.gov/laws-regulations/summary-clean-air-act) regulates air emissions from mobile sources, such as cars, and stationary sources, such as refineries and power plants. *Please note, in this report we are only utilizing data from stationary air emission sources.* For the CAA, violations are most commonly recognized via inspections. Infrequent inspection usually results in fewer identified violations. If CAA violations have decreased, make sure to check whether inspections have also decreased as recent cuts in inspections are likely related to drops in CAA violations. Unless thorough inspections are occurring regularly, fewer violations does not necessarily mean air quality has improved.
[More info on CAA](https://docs.google.com/presentation/d/1MzRQf3QeJqmYMSttdk0ghrXeOmOZgOV_MTynl-ri6Ik/edit?usp=sharing)
</div>
<h2>There are `r region$get_active_facilities('CAA')` facilities currently reporting under the CAA in this state.</h2>
```{r, fig.height = 5, fig.width = 8, fig.align = "center"}
hasCAAviolations <- FALSE
nrows_df <- nrow( CAAviolations )
if ( nrows_df > 0 ) {
hasCAAviolations <- TRUE
#clean up data
CAAviolations <- CAAviolations %>%
mutate(President = which_president(Year))
vCAAgraph <- ggplot(CAAviolations, mapping=aes(x=factor(Year), y=Count, fill=President, group=1))+
geom_bar(stat="identity", show.legend = FALSE, alpha=.3)+
scale_fill_manual(values=president_colors,breaks=c('Bush', 'Obama', 'Trump', 'Biden'))+
labs(y=" # Violations", x="Year", title="CAA Violations\n", subtitle ="Very incomplete data")+
scale_y_continuous(expand=c(0,0), limits=c(0,max(CAAviolations$Count+(.2*max(CAAviolations$Count)))))+
scale_x_discrete(breaks=c(2004,2008,2012, 2016, 2020))+
theme_meg()+
theme(axis.text.x=element_text(size=10),
axis.title.x = element_blank(), plot.subtitle = element_text(hjust=.5))
}
```
```{r, fig.height = 5, fig.width = 8, fig.align = "center"}
hasCAAinspections <- FALSE
nrows_df <- nrow( CAAinspections )
if ( nrows_df > 0 ) {
hasCAAinspections <- TRUE
#clean up data
CAAinspections <- CAAinspections %>%
mutate(President = which_president(Year))
iCAAgraph <- ggplot(CAAinspections, mapping=aes(x=factor(Year), y=Count, fill=President, group=1))+
geom_bar(stat="identity", show.legend = FALSE, alpha=.6)+
scale_fill_manual(values=president_colors,breaks=c('Bush', 'Obama', 'Trump', 'Biden'))+
labs(y=" # Inspections", x="Year", title="CAA Inspections\n", subtitle ="Potentially incomplete data")+
#ggtitle("CAA Inspections")+
scale_y_continuous(expand=c(0,0), limits=c(0,max(CAAinspections$Count+(.2*max(CAAinspections$Count)))))+
scale_x_discrete(breaks=c(2004,2008,2012, 2016, 2020))+
theme_meg()+
theme(axis.text.x=element_text(size=10),
axis.title.x = element_blank(), plot.subtitle = element_text(hjust=.5))
}
```
```{r, fig.height = 5, fig.width = 8, fig.align = "center"}
hasCAAenforcement <- FALSE
nrows_df <- nrow( CAAenforcement_clean )
if ( nrows_df > 0 ) {
hasCAAenforcement <- TRUE
#clean up data
CAAenforcement <- CAAenforcement_clean
CAAenforcement <- CAAenforcement %>%
mutate(President = which_president(Year))
#adjust for inflation
CAAenforcement <- merge(CAAenforcement, inflation, by.x='Year', by.y='index', all.x=TRUE)
CAAenforcement$inflationadjust <- as.numeric(CAAenforcement$Amount*CAAenforcement$base)
##make a new amount column /1000
CAAenforcement$Amountinthousands <- ((CAAenforcement$inflationadjust)/1000)
CAAenforcement$Amountinthousands <-round(CAAenforcement$Amountinthousands,2)
eCAAgraph <- ggplot(CAAenforcement, mapping=aes(x=factor(Year), y=Count, fill=President, group=1))+
geom_bar(stat="identity", show.legend = FALSE, alpha=.6)+
scale_fill_manual(values=president_colors,breaks=c('Bush', 'Obama', 'Trump', 'Biden'))+
labs(y=" # Actions", x="Year", title="CAA Enforcement Actions\n", subtitle ="Potentially incomplete data")+
scale_y_continuous(expand=c(0,0), limits=c(0,max(CAAenforcement$Count+(.2*max(CAAenforcement$Count)))))+
scale_x_discrete(breaks=c(2004,2008,2012, 2016, 2020))+
theme_meg()+
theme(axis.text.x=element_text(size=10),
axis.title.x = element_blank(), plot.subtitle = element_text(hjust=.5))
fineCAAgraph <- ggplot(CAAenforcement, mapping=aes(x=factor(Year), y=Amountinthousands, fill=President, group=1))+
geom_bar(stat="identity", alpha=.6)+
scale_fill_manual(values=president_colors,breaks=c('Bush', 'Obama', 'Trump', 'Biden'), guide=guide_legend(breaks=c("Bush","Obama","Trump","Biden")))+
labs(y=" Fines ($1000s)", x="Year", title="CAA Fines\n", subtitle ="Potentially incomplete data", caption="Values adjusted for inflation. Note, the y-axis reports values in\n1000's. A value of $2000 represents $2,000,000 (2 million dollars).")+
scale_y_continuous(expand=c(0,0), limits=c(0,max(CAAenforcement$Amountinthousands+(.2*max(CAAenforcement$Amountinthousands)))))+
scale_x_discrete(breaks=c(2004,2008,2012, 2016, 2020))+
theme_meg()+
theme(axis.text.x=element_text(size=10),
axis.title.x = element_blank(), plot.subtitle = element_text(hjust=.5), plot.caption = element_text(size=8))
}
```
```{r, fig.height = 5, fig.width = 8, fig.align = "center"}
(iCAAgraph | vCAAgraph) / (eCAAgraph | fineCAAgraph)
```
These figures show patterns of CAA inspections, violations, enforcement actions and fines in this state since 2001 based on available EPA data (see page 10). The bars are colored by president. Figure transparency illustrates data reliability: the more transparent, the more uncertain the data. Data on CAA violations is particularly unreliable as emissions are often not directly monitored but are estimates. Inspection, enforcement, and fine data can be unreliable because state reporting to ECHO may be incomplete.For access to the Jupyter Notebook which pulls data from ECHO at the state and congressional district level, click [here](https://colab.research.google.com/github/edgi-govdata-archiving/ECHO-Cross-Program/blob/master/AllPrograms.ipynb).
\pagebreak
<br />
<hr style="height:3px;border-width:0;margin-left:15px; margin-right:15px;color: #C1E0D7;background-color: #C1E0D7; margin-top: 0em; margin-bottom: 0em">
<h4>Report Generated on `r format(Sys.time(), '%B %d, %Y')`<span style="padding-left:400px">Page 7</span></h4>
# Clean Water Act
<div class="text-box-info">
The [Clean Water Act (CWA)](https://www.epa.gov/laws-regulations/summary-clean-water-act) establishes quality standards for surface waters. In this report, we focus on CWA’s National Pollutant Discharge Elimination System (NPDES) which permits facilities to discharge certain kinds and amounts of pollutants. Unlike the CAA, under the CWA effluent (waste emissions) is directly measured and routinely reported electronically to ECHO. CWA violations are automatically triggered if data is not submitted and if contaminant levels in effluent exceed the permitted amount. Such CWA violations can lead to inspections. [More info on CWA](https://docs.google.com/presentation/d/1g6ZN3B5jvs3F1VAigiUtNNezjXdJnzuELfo9Deo9Y2w/edit?usp=sharing)
</div>
<h2>There are `r region$get_active_facilities('CWA') ` facilities currently reporting under the
CWA in this state.</h2>
```{r, fig.height = 5, fig.width = 8, fig.align = "center"}
hasCWAviolations <- FALSE
nrows_df <- nrow( CWAviolations )
if ( nrows_df > 0 ) {
hasCWAviolations <- TRUE
#clean up data
# data cleaned elsewhere
#plot
vCWAgraph <- ggplot(CWAviolations, mapping=aes(x=factor(Year), y=Count, fill=President, group=1))+
geom_bar(stat="identity", show.legend = FALSE)+
scale_fill_manual(values=president_colors,breaks=c('Bush', 'Obama', 'Trump', 'Biden'))+
labs(y=" # Violations", x="Year", title="CWA Violations\n", subtitle ="Mostly complete data")+
scale_y_continuous(expand=c(0,0), limits=c(0,max(CWAviolations$Count+(.2*max(CWAviolations$Count)))))+
scale_x_discrete(breaks=c(2004,2008,2012,2016,2020))+
theme_meg()+
theme(axis.text.x=element_text(size=10),
axis.title.x = element_blank(), plot.subtitle = element_text(hjust=.5))
}
```
```{r, fig.height = 5, fig.width = 8, fig.align = "center"}
hasCWAinspections <- FALSE
nrows_df <- nrow( CWAinspections )
if ( nrows_df > 0 ) {
hasCWAinspections <- TRUE
#clean up data
names(CWAinspections)[1] <- "Year"
CWAinspections <- CWAinspections %>%
mutate(President = which_president(Year))
iCWAgraph <- ggplot(CWAinspections, mapping=aes(x=factor(Year), y=Count, fill=President, group=1))+
geom_bar(stat="identity", show.legend = FALSE, alpha=.6)+
scale_fill_manual(values=president_colors,breaks=c('Bush', 'Obama', 'Trump', 'Biden'))+
labs(y=" # Inspections", x="Year", title="CWA Inspections\n", subtitle ="Potentially incomplete data")+
ggtitle("CWA Inspections")+
scale_y_continuous(expand=c(0,0), limits=c(0,max(CWAinspections$Count+(.2*max(CWAinspections$Count)))))+
scale_x_discrete(breaks=c(2004,2008,2012,2016, 2020))+
theme_meg()+
theme(axis.text.x=element_text(size=10),
axis.title.x = element_blank(), plot.subtitle = element_text(hjust=.5))
}
```
```{r, fig.height = 5, fig.width = 8, fig.align = "center"}
hasCWAenforcement <- FALSE
nrows_df <- nrow( CWAenforcement_clean )
if ( nrows_df > 0 ) {
hasCWAenforcement <- TRUE