plot_county_application: Plot pesticide application by county.

Description Usage Arguments Value Examples

View source: R/05-plot.R

Description

plot_county_application returns a plot of applied pesticides (either the sum of all active ingredients present in the input pull_clean_pur data frame, a specified chemical class, or a specified active ingredient). Application is summed by section or township. PLS units can be shaded by amount or by percentile.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
plot_county_application(
  clean_pur_df,
  county = NULL,
  pls = NULL,
  color_by = "amount",
  percentile = c(0.25, 0.5, 0.75),
  start_date = NULL,
  end_date = NULL,
  chemicals = "all",
  fill = "viridis",
  crop = FALSE,
  alpha = 1,
  ggmap_background = TRUE,
  polygon_color = "grey",
  polygon_size = 0.25,
  ...
)

Arguments

clean_pur_df

A data frame returned by pull_clean_pur.

county

Optional. If your clean_pur_df data frame contains data for multiple counties, this argument specifies which county you would like to plot application for. Either a PUR county name or county code. California names and county codes as they appear in PUR data sets can be found in the county_codes data set available with this package.

pls

Optional. Either "section" or "township". If your clean_pur_df data frame has both a section and township column, the pls argument specifies which pls unit you would like to plot application for (the default in this case is "section"). If you pulled data specifying unit = "township", application will be plotted by township.

color_by

Either "amount" (the default) or "percentile". Specifies whether you would like application amounts to be colored according to amount, resulting in a gradient legend, or by the percentile that they fall into for the given data set and date range. You can specify percentile cutpoints with the percentile argument.

percentile

A numeric vector in (0, 1) specifying percentile cutpoints if color_by = "percentile". The default is c(0.25, 0.5, 0.75), which results in four categories: < 25th percentile, >= 25th to < 50th, >= 50th to < 75th, and >= 75th.

start_date

Optional. "yyyy-mm-dd" giving a starting date for the date range that you would like to map application for. The default is to plot application for the entire date range in your clean_pur_df data frame.

end_date

Optional. "yyyy-mm-dd" giving an ending date for the date range that you would like to plot application for. The default is to plot application for the entire date range in your clean_pur_df data frame.

chemicals

Either "all" (the default) to plot summed active ingredients present in your clean_pur_df data frame, a chemical class present in the chemical_class column of the clean_pur_df data frame, or a specific active ingredient present in the chemname column of the clean_pur_df data frame.

fill

A palette from the colormap package. The default is "viridis". To see colormap palette options, visit https://bhaskarvk.github.io/colormap/ or run colormap::colormaps.

crop

TRUE / FALSE for whether you would like your plot zoomed in on sections or townships with recorded application data.

alpha

A number in [0,1] specifying the transparency of fill colors. Numbers closer to 0 will result in more transparency. The default is 1.

ggmap_background

TRUE / FALSE for whether you would like a ggmap background.

polygon_color

passed to the color argument of ggplot2::geom_polygon.

polygon_size

passed to the size argument of ggplot2::geom_polygon.

...

Used internally.

Value

A list with three elements:

map

A plot of the county with application summed by section or township and colored by amount or by percentile.

data

A data frame with the plotted application data.

cutoff_values

A data frame with two columns: percentile and kg, giving the cut points for each percentile in the clean_pur_df for the specified chemicals. This element of the list is not returned if color_by = "amount".

Examples

 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
library(magrittr)

fresno_spdf <- readRDS(system.file("extdata", "fresno_spdf.rds",
                                   package = "purexposure"))
fresno_clean <- readRDS(system.file("extdata", "fresno_clean.rds",
                                    package = "purexposure"))
fresno_list <- fresno_clean %>% plot_county_application(spdf = fresno_spdf)

# plot all active ingredients
fresno_df <- pull_clean_pur(2000:2001, "fresno")
fresno_list <- plot_county_application(fresno_df,
                                      color_by = "percentile",
                                      percentile = c(0.2, 0.4, 0.6, 0.8))
fresno_list$map
head(fresno_list$data)
fresno_list$cutoff_values

# plot a specific active ingredient
fresno_list2 <- plot_county_application(fresno_df, pls = "township",
                                       chemicals = "sulfur",
                                       fill = "plasma")
fresno_list2$map

# plot a chemical class
chemical_class_df <- purrr::map2_dfr(2010, c("methidathion", "parathion",
                                             "naled", "malathion",
                                             "trichlorfon"),
                                     find_chemical_codes) 
     dplyr::mutate(chemical_class = "organophosphates") 
     dplyr::select(-chemical)
op_yuba <- pull_clean_pur(2010, "yuba",
                          chemicals = chemical_class_df$chemname,
                          verbose = F, sum_application = T,
                          sum = "chemical_class",
                          chemical_class = chemical_class_df) 
   plot_county_application()
op_yuba$map

leighseverson/purexposure documentation built on Aug. 13, 2021, 6:34 p.m.