1. Load libraries

2. Inits

3. Define WI Region & Season of interest

4. Load 2023 ERD & SRD & Solar data

5. Identify which ERD checklists (in B) are within a specified distance of any Solar installations (in A)

Compute distance matrix

Find points in B (erd) within the specified distance from any point in A (solar)

Extract the subset of points in B that are within the specified distance

Report Minimum dist bet B and all point in A

6. Number of checklists by array and year

B.count = B %>% count(checklist_id, check.year, check.year.f, PV_project, PV_install_year, PV_install_year.f) 
B.count = B.count %>%
  group_by(PV_project, PV_install_year.f, check.year.f, PV_install_year, check.year) %>%
    summarise(no.check=sum(n))
## `summarise()` has grouped output by 'PV_project', 'PV_install_year.f',
## 'check.year.f', 'PV_install_year'. You can override using the `.groups`
## argument.
#names(B.count)
#B.count
count.FW = ggplot(B.count, aes(x=check.year.f, y=no.check))+
  geom_jitter() + 
      theme(legend.position="none") +
    theme(axis.text.x = element_text(angle = 90)) +
    labs(x = "", title = "number of checklists over time by PV project with installation date") +
  facet_wrap(~PV_project)

count.FW +    geom_vline(aes(xintercept = PV_install_year.f),data=B.count)

ggplot(B.count, aes(x=check.year.f, y=no.check, color = PV_project))+
  geom_jitter() + 
      theme(legend.position="none") +
    theme(axis.text.x = element_text(angle = 90)) 

7. [I can’t get this to work] Summary table and plot of number of checklists pre installation v post

8. Nighttime lights pre-post installation

B$ntl = erd$ntl_mean

ntl.count = B %>% select(check.year.f, ntl, PV_install_year, PV_project) %>%
  group_by(PV_install_year)

#names(ntl.count)
#ntl.count
ntl.count$PV_install_year.f = factor(ntl.count$PV_install_year)

ntl.plot = ggplot(ntl.count, aes(x=check.year.f, y=ntl))+
  geom_jitter() + 
  theme(axis.text.x = element_text(angle = 90)) +
    labs(x = "", title = "night time lights over time by PV project with installation date") +
  facet_wrap(~PV_project) 

ntl.plot +    geom_vline(aes(xintercept = PV_install_year.f), data=ntl.count)

9. Rivers and lakes pre-post installation

B$rivers = erd$astwbd_c2_pland

rivers = B %>% select(check.year.f, rivers, PV_install_year, PV_project) %>%
  group_by(PV_install_year)

#names(rivers)
#rivers
rivers$PV_install_year.f = factor(rivers$PV_install_year)

rivers.plot = ggplot(rivers, aes(x=check.year.f, y=rivers))+
  geom_jitter() + 
    theme(axis.text.x = element_text(angle = 90)) +
      labs(x = "", title = "rivers over time by PV project with installation date") +
  facet_wrap(~PV_project) 

rivers.plot +    geom_vline(aes(xintercept = PV_install_year.f), data=rivers)

B$lakes = erd$astwbd_c3_pland

lakes = B %>% select(check.year.f, lakes, PV_install_year, PV_project) %>%
  group_by(PV_install_year)

#names(lakes)
#lakes
lakes$PV_install_year.f = factor(lakes$PV_install_year)

lakes.plot = ggplot(lakes, aes(x=check.year.f, y=lakes))+
  geom_jitter() + 
    theme(axis.text.x = element_text(angle = 90)) +
    labs(x = "", title = "lakes over time by PV project with installation date") +
  facet_wrap(~PV_project) 

lakes.plot +    geom_vline(aes(xintercept = PV_install_year.f), data=lakes)

## 10. Greeness pre-post installation

B$evig = erd$evi_median

evi = B %>% select(check.year.f, evig, PV_install_year, PV_project) %>%
  group_by(PV_install_year)

#names(evi)
#evi
evi$PV_install_year.f = factor(evi$PV_install_year)

evi.plot = ggplot(evi, aes(x=check.year.f, y=evig))+
  geom_jitter() + 
    theme(axis.text.x = element_text(angle = 90)) +
    labs(x = "", title = "greenness over time by PV project with installation date") +
  facet_wrap(~PV_project) 

evi.plot +    geom_vline(aes(xintercept = PV_install_year.f), data=evi)

11. Elevation across installations

B$elev = erd$elevation_30m_median

elevn = B %>% select(check.year.f, elev, PV_install_year, PV_project) %>%
  group_by(PV_install_year)

#names(elev)
#elev
elevn$PV_install_year.f = factor(elevn$PV_install_year)

elevn.plot = ggplot(elevn, aes(x=PV_project, y=elev))+
  geom_boxplot() + 
    labs(x = "", title = "elevation by PV project") +
    theme(axis.text.x = element_text(angle = 90)) 
elevn.plot