generated from edgi-govdata-archiving/Template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
NewGraphs.rmd
1269 lines (1034 loc) · 71.1 KB
/
NewGraphs.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"
output:
html_paged:
number_sections: false
css: ["custom_current.css"]
params:
cd_state: "NY12"
full_name: "New York's 12th District"
state: "NY"
district: "12"
---
```{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()
CD <- substr(params$cd_state,3,4)
target_year <- '2020'
full_name <- params$full_name
# States with a single congressional district: The leg_info.db
# has the district as "00", per 'https://theunitedstates.io/congress-legislators/legislators-current.json'.
# The regions.db has the district as 1, per EPA's ECHO_EXPORTER.
# So if the CD variable is "00", we will use a Region_CD variable
# when getting the region data.
Region_CD <- CD
if ( Region_CD == "00" ) Region_CD <- "01"
output_loc <- paste('Output/',params$cd_state,"/",sep="")
dir.create(output_loc)
conn <- dbConnect( RSQLite::SQLite(), "leg_info.db")
legislator = dbGetQuery( conn, "select * from legislators where cd_state=?",
params=c( params$cd_state ))
leg_info <- list( name=legislator$name, party=legislator$party,
sen_class=legislator$sen_class,
since_date=legislator$since_date, since_year=legislator$since_year,
official_url=legislator$official_url,
govtrack_url=legislator$govtrack_url,
wikipedia_url=legislator$wikipedia_url,
opensecrets_url=legislator$opensecrets_url,
twitter=legislator$twitter,
facebook=legislator$facebook )
committee_membership = dbGetQuery( conn,
"select * from committee_members where bioguide_id = ?",
params=c(legislator$bioguide_id))
committees <- list()
if ( nrow( committee_membership ) > 0 ) {
for ( row in 1:nrow( committee_membership )) {
committee_id <- committee_membership[ row, "committee_id" ]
committee <- dbGetQuery( conn,
"select * from committees where committee_id = ?",
params=c(committee_id))
if ( committee$include == 0 )
next;
subcommittee_id <- committee_membership[ row, "subcommittee_id" ]
if ( is.null( subcommittee_id ))
next;
if ( nchar( subcommittee_id ) == 0 ) {
committees[[committee_id]] <- list( committee=committee )
} else {
subcommittee <- dbGetQuery( conn,
"select *,? as rank from sub_committees where committee_id=? and subcommittee_id=?",
params=c(committee_membership[row,"rank"],committee_id,subcommittee_id))
committees[[committee_id]] <- list.append( committees[[committee_id]],
subcommittee )
}
}
}
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='Congressional District', value=Region_CD, state=params$state, programs=c('CAA', 'CWA', 'RCRA'))
target_year_int <- strtoi( target_year )
USAinspectionsper1000_All <- region$get_per_1000( 'inspections', 'USA', target_year_int )
inspectionsper1000_state <- region$get_per_1000( 'inspections', 'State', target_year_int )
inspectionsper1000_cd <- region$get_per_1000( 'inspections', 'CD', 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 )
violationsper1000_cd <- region$get_per_1000( 'violations', 'CD', target_year_int )
inflation <- region$get_inflation( target_year_int )
CWAper1000 <- region$get_cwa_per_1000( target_year_int )
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 )
enforcement <- region$get_events( 'enforcements', 'All', 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 )
CAArecurring <- region$get_recurring_violations( 'CAA' )
CWArecurring <- region$get_recurring_violations( 'CWA' )
RCRArecurring <- region$get_recurring_violations( 'RCRA' )
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' )
this_state <- params$state
```
```{python echo=FALSE}
from create_df import create_df
cwa_insp_years = create_df(region_type='Congressional District',data_type='inspections',
y_field='Count',program='CWA',states=[r.this_state,],region_selected=r.Region_CD)
cwa_viol_years = create_df(region_type='Congressional District',data_type='violations',
y_field='Count',program='CWA',states=[r.this_state,],region_selected=r.Region_CD)
cwa_enf_count_years = create_df(region_type='Congressional District',data_type='enforcements',
y_field='Count',program='CWA',states=[r.this_state,],region_selected=r.Region_CD)
cwa_enf_count_years = cwa_enf_count_years.drop('Amount',1)
cwa_enf_dollar_years = create_df(region_type='Congressional District',data_type='enforcements',
y_field='Amount',program='CWA',states=[r.this_state,],region_selected=r.Region_CD)
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.
cwa_enf_dollar_years[r.Region_CD] = cwa_enf_dollar_years[r.Region_CD]/1000.
```
```{r echo=FALSE, include=FALSE}
cwa_insp_years <- melt(py$cwa_insp_years, id=c("Year"))
cwa_viol_years <- melt(py$cwa_viol_years, id=c("Year"))
cwa_enf_count_years <- melt(py$cwa_enf_count_years, id=c("Year"))
cwa_enf_dollar_years <- melt(py$cwa_enf_dollar_years, id=c("Year"))
```
```{r echo=FALSE, include=FALSE}
# Color selection
cols <- c("#D43F3A", "#EEA236", "#5CB85C", "#46B8DA")
graph1 <- ggplot(cwa_insp_years, aes(x = Year, y = value, color = variable)) +
geom_line() +
scale_color_manual(values = cols) +
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 = cols) +
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 = cols) +
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 = cols) +
guides(color = guide_legend(title = "Regions")) +
labs(y="Fines ($1000)", x="Year", title="CWA - Enforcement Fines Per Facility")
```
```{r echo=FALSE}
##getting %difference CWA violations
CWAviolations <- CWAviolations %>%
mutate(
President = case_when(
Year < 2009 ~ "Bush",
Year < 2017 & Year > 2008 ~ "Obama",
Year > 2016 ~ "Trump"
))
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 = case_when(
Year < 2009 ~ "Bush",
Year < 2017 & Year > 2008 ~ "Obama",
Year > 2016 ~ "Trump"
))
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 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))
}
if ( CD == '00' ) {
map_src <- paste('State_maps/',params$state,'_map.png',sep='')
} else {
map_src <- paste('CD_maps/',params$state,CD,'_map.png',sep='')
}
```
<div class="title"><span style="padding-left: 100px">
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: .5em; margin-bottom: 0em">
##### `r full_name`; seat held by `r leg_info$name` since `r leg_info$since_year`
<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 EPA. Provided states are enforcing the above laws, it is because EPA has delegated that authority to them. EPA must ensure that states are doing their job. Congress must ensure that EPA is doing its job. And the public must have accurate data from states and 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 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 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
<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 2</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`, and congressional district `r Region_CD`,
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">`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>
*see data limitations page for metric calculations
\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 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/CD
#will need to change this to make compatible for CD and State one template
CWArecurring2 <- CWArecurring[-is.na(CWArecurring$CD), ]
CWArecurring2[5] <-round(CWArecurring2[5],1)
##until we fix the dataframe that is called from region.db, the above two lines make the under the clean water act statement
CWArecurring <- CWArecurring %>%
select(CD,Facilities, Percent)
names(CWArecurring)[1] <- "Region"
CWArecurring[1,1] <- as.character("Rest of State")
CWArecurring[2,1] <- as.character(paste(params$state,CD))
CWArecurring[2,4] <- as.character(paste(params$state,CD))
CWArecurring$RecurringViolators <- (as.numeric(CWArecurring[1,2]-CWArecurring[2,2]))
CWArecurring[2,5] <- as.numeric(CWArecurring[2,2])
CWArecurring$Proportional <- (as.numeric((100/(CWArecurring[1,2]))*CWArecurring[1,5]))
CWArecurring[2,6] <- as.numeric(100-CWArecurring[1,6])
CWArecurring[3] <-round(CWArecurring[3],0)
#we don't currently utilize the recurring # or % under the CAA or RCRA b/c of the unreliability of the data. We do call that data from the regions.db, however. If and when this is needed, you can use the code above from CWA to replicate the process for these other acts
```
```{r echo=FALSE}
##getting %difference effluent violations
#[9:11,2] Obama
# [17:19,2] Trump
effluentviolations <- CWAviolations # SH
effluentchange <- data.frame("Obama Average" =mean(effluentviolations[9:12,2]),
"Trump Average" =mean(effluentviolations[17:20,2])) # SH
effluentchange$PercentDifference <- as.numeric(100*(effluentchange[1,2]-effluentchange[1,1])/
effluentchange[1,1])
effluentchange[,1:3] <-round(effluentchange[,1:3],2)
#then simple plot
effluentgraph <- ggplot(effluentviolations, mapping=aes(x=factor(Year),
y=Count, fill=President, group=1))+
geom_bar(stat="identity")+
scale_fill_manual(values=c("#450d54", "#22908d", "#e56d13"))+
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=9), 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)
#first add in the Presidential Years
inspections <- inspections %>%
mutate(
President = case_when(
Year < 2009 ~ "Bush",
Year < 2017 & Year > 2008 ~ "Obama",
Year > 2016 ~ "Trump"
))
#then simple plot
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=c("#450d54", "#22908d", "#e56d13"))+
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(hjust=.5, size=9), plot.title =
element_text(lineheight = .1, size=10)) # SH
#enforcement
#[9:11,2] Obama
# [17:19,2] Trump
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])) # SH
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 <- merge(enforcement, inflation, by.x='Year', by.y='index', all.x=TRUE)
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)
#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=c("#450d54", "#22908d", "#e56d13"))+
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=3)+
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=c("#450d54", "#22908d", "#e56d13"))+
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 CWArecurring2[1,2]` facilities, representing `r CWArecurring2[1,5]`% of all regulated facilities in `r params$cd_state`,</span> were in violation for <span style="color:#569b5e">at least 9 months of the last 3 years.</span></h3>
```{r echo=FALSE, out.width= "95%", out.extra='style="float:center; padding:0px"'}
effluentgraph/inspectiongraph/enforcementactiongraph/enforcementfinegraph
```
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
<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 4</span></h4>
# This District 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")
names(inspectionsper1000_cd)[2] <- "Inspectionsper1000"
inspectionsper1000_cd$Region <- as.factor("Congressional District")
inspectionsper1000 <- rbind(USAinspectionsper1000_All, inspectionsper1000_state, inspectionsper1000_cd)
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("#999999" , "#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")
names(violationsper1000_cd)[2] <- "violationsper1000"
violationsper1000_cd$Region <- as.factor("Congressional District")
violationsper1000 <- rbind(USAviolationsper1000_All, violationsper1000_state, violationsper1000_cd)
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("#999999" , "#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))
```
```{r echo=FALSE, out.width= "95%", out.extra='style="float:center; padding:0px"'}
inspect1000bar / violations1000bar
knitr::opts_chunk$set(fig.width = 10,fig.height = 6)
```
<br />
These two charts show how inspections and violations in this district compare to the national and state averages 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 software which pulls data from ECHO, see the Github repository [here](https://github.com/edgi-govdata-archiving/EEW-ReportCard-Data).
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
<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 5</span></h4>
<h1><span style="margin-bottom:0px; padding-bottom:0px">Recent Non-Compliance in this District</span></h1>
<font size="2">These figures show the ten facilities in this district 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 )
if ( nrows_df > 0 ) {
CAAbadactors <- CAAbadactors[-c(9:100),] # 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;">[`r na.omit(CAAbadactors[1,7]) `](`r na.omit(CAAbadactors[1,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(CAAbadactors[2,7]) `](`r na.omit(CAAbadactors[2,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(CAAbadactors[3,7]) `](`r na.omit(CAAbadactors[3,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(CAAbadactors[4,7]) `](`r na.omit(CAAbadactors[4,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(CAAbadactors[5,7]) `](`r na.omit(CAAbadactors[5,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(CAAbadactors[6,7]) `](`r na.omit(CAAbadactors[6,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(CAAbadactors[7,7]) `](`r na.omit(CAAbadactors[7,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(CAAbadactors[8,7]) `](`r na.omit(CAAbadactors[8,4]) `)<br /></p>
<br />
<br />
<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 )
if ( nrows_df > 0 ) {
RCRAbadactors <- RCRAbadactors[-c(9:100),] # 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;">[`r na.omit(RCRAbadactors[1,7]) `](`r na.omit(RCRAbadactors[1,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(RCRAbadactors[2,7]) `](`r na.omit(RCRAbadactors[2,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(RCRAbadactors[3,7]) `](`r na.omit(RCRAbadactors[3,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(RCRAbadactors[4,7]) `](`r na.omit(RCRAbadactors[4,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(RCRAbadactors[5,7]) `](`r na.omit(RCRAbadactors[5,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(RCRAbadactors[6,7]) `](`r na.omit(RCRAbadactors[6,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(RCRAbadactors[7,7]) `](`r na.omit(RCRAbadactors[7,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(RCRAbadactors[8,7]) `](`r na.omit(RCRAbadactors[8,4]) `)<br /></p>
<br />
<br />
<br />
<br />
<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 )
if ( nrows_df > 0 ) {
CWAbadactors <- CWAbadactors[-c(9:100),] # 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;">[`r na.omit(CWAbadactors[1,7]) `](`r na.omit(CWAbadactors[1,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(CWAbadactors[2,7]) `](`r na.omit(CWAbadactors[2,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(CWAbadactors[3,7]) `](`r na.omit(CWAbadactors[3,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(CWAbadactors[4,7]) `](`r na.omit(CWAbadactors[4,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(CWAbadactors[5,7]) `](`r na.omit(CWAbadactors[5,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(CWAbadactors[6,7]) `](`r na.omit(CWAbadactors[6,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(CWAbadactors[7,7]) `](`r na.omit(CWAbadactors[7,4]) `)<br /></p>
<p style="text-align: right;">[`r na.omit(CWAbadactors[8,7]) `](`r na.omit(CWAbadactors[8,4]) `)<br /></p>
<br />
<br />
<br />
<br />
\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 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 district.</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 = case_when(
Year < 2009 ~ "Bush",
Year < 2017 & Year > 2008 ~ "Obama",
Year > 2016 ~ "Trump"
))
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=c("#450d54", "#22908d", "#e56d13"))+
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 = case_when(
Year < 2009 ~ "Bush",
Year < 2017 & Year > 2008 ~ "Obama",
Year > 2016 ~ "Trump"
))
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=c("#450d54", "#22908d", "#e56d13"))+
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 = case_when(
Year < 2009 ~ "Bush",
Year < 2017 & Year > 2008 ~ "Obama",
Year > 2016 ~ "Trump"
))
#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=c("#450d54", "#22908d", "#e56d13"))+
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=c("#450d54", "#22908d", "#e56d13"))+
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 district 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 district.</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=c("#450d54", "#22908d", "#e56d13"))+
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[-c(20),]
CWAinspections$President <- as.character("Bush")
CWAinspections[9:16,3] <- as.character("Obama")
CWAinspections[17:20,3] <- as.character("Trump")
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=c("#450d54", "#22908d", "#e56d13"))+
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
#clean up data
CWAenforcement <- CWAenforcement_clean
CWAenforcement <- CWAenforcement[-c(20),]
CWAenforcement$President <- as.character("Bush")
CWAenforcement[8:16,4] <- as.character("Obama")
CWAenforcement[17:20,4] <- as.character("Trump")
#adjust for inflation
CWAenforcement <- merge(CWAenforcement, inflation, by.x='Year', by.y='index', all.x=TRUE)
CWAenforcement$inflationadjust <- as.numeric(CWAenforcement$Amount*CWAenforcement$base)
##make a new amount column /1000
CWAenforcement$Amountinthousands <- ((CWAenforcement$inflationadjust)/1000)
CWAenforcement$Amountinthousands <-round(CWAenforcement$Amountinthousands,2)
eCWAgraph <- ggplot(CWAenforcement, mapping=aes(x=factor(Year), y=Count, fill=President, group=1))+
geom_bar(stat="identity", show.legend = FALSE, alpha=.6)+
scale_fill_manual(values=c("#450d54", "#22908d", "#e56d13"))+
labs(y=" # Actions", x="Year", title="CWA Enforcement Actions\n", subtitle="Potentially incomplete data")+
#ggtitle("CWA Enforcement Actions")+
scale_y_continuous(expand=c(0,0), limits=c(0,max(CWAenforcement$Count+(.2*max(CWAenforcement$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))
fineCWAgraph <- ggplot(CWAenforcement, mapping=aes(x=factor(Year), y=Amountinthousands, fill=President, group=1))+
geom_bar(stat="identity", alpha=.6)+
scale_fill_manual(values=c("#450d54", "#22908d", "#e56d13"))+
labs(y=" Fines($1000s)", x="Year", title="CWA 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).")+
#ggtitle("CWA Fines")+
scale_y_continuous(expand=c(0,0), limits=c(0,max(CWAenforcement$Amountinthousands+(.2*max(CWAenforcement$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"}
no_enforcement <- ""
if ( hasCWAenforcement ) {
(iCWAgraph | vCWAgraph) / (eCWAgraph | fineCWAgraph)
} else {
no_enforcement <- "<h3><i>[There is no enforcement or fine data for CWA in this district.]</i></h3>"
(iCWAgraph | vCWAgraph)
}
```
`r no_enforcement`
These figures show patterns of Clean Water Act inspections, violations, enforcement actions and fines in this district 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 CWA violations is particularly reliable as effluent violations are automatically reported to EPA.
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).
<br />
<br />
\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">