knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 6,
  fig.height = 4
)

Import libraries and data

require(ggfertilizer)
require(ggplot2)
require(ggsn)
data("us_fertilizer_county")

Plot P input from manure maps for carolinas

Year = 1997
Nutrient = "N"
Farm_Type = "farm"
Input_Type = "manure"
level  = "county" 
carolinas = c("NC", "SC")

# draw the maps
state_plot <- map_us_fertilizer(data = us_fertilizer_county, Year = Year, Nutrient = Nutrient,
                             Farm_Type = Farm_Type, Input_Type = Input_Type, State = carolinas,
                             viridis_palette = "inferno", level = level) +

  ggtitle(paste(Nutrient, " from ", Input_Type, " input to ", Farm_Type, " in the year of ",Year,
                     " at ", level, " level",sep = ""))
state_plot

We can also add a north label and a scale bar for the map from R package ggsn.

Year = 1997
Nutrient = "N"
Farm_Type = "farm"
Input_Type = "manure"
level  = "county" 
carolinas = c("NC", "SC")

# draw the maps
state_plot <- map_us_fertilizer(data = us_fertilizer_county, Year = Year, Nutrient = Nutrient,
                             Farm_Type = Farm_Type, Input_Type = Input_Type, State = carolinas,
                             viridis_palette = "inferno", level = level, add_north = TRUE) +

  ggtitle(paste(Nutrient, " from ", Input_Type, " input to ", Farm_Type, " in the year of ",Year,
                     " at ", level, " level",sep = ""))

state_plot + 
  north(data = state_plot$states_shape, location = "topleft")+
  scalebar(data = state_plot$states_shape,  
           dist = 80, dd2km = TRUE, model = 'WGS84', st.size = 3)

Plot fertilizer maps for midwest states

Year = c(1950, 1970, 1990, 2010)
Nutrient = "N"
Farm_Type = "farm"
Input_Type = "fertilizer"
level  = "state" 
facet  = "Year"
midwest_states = c("OH", "MI", "IN", "WI", "IL", "MN", "IA", "MI", "ND", "SD", "NE", "KS")
us_fertilizer_county$Year = as.numeric(us_fertilizer_county$Year)
# draw the maps
state_plot <- map_us_fertilizer(data = us_fertilizer_county, Year = Year, Nutrient = Nutrient,
                             Farm_Type = Farm_Type, Input_Type = Input_Type, State = midwest_states,
                             viridis_palette = "inferno", level = level ) +
  ggtitle(paste(Nutrient, " from ", Input_Type, " input to ", Farm_Type,
                     " at ", level, " level",sep = ""))
state_plot

Plot fertilizer use maps for certain counties.

Year = 1997
Nutrient = "P"
Farm_Type = "farm"
Input_Type = "manure"
level  = "county" 
carolinas = "NC"
county = c( "duplin", "beaufort",  "Lenoir", "pender", "Bladen", "Brunswick",
            "Carteret", "Columbus", "jones", "New Hanover", "Onslow", "Pamlico", "Pender",
           "Robeson", "Sampson", "Wayne", "Wilson", "Craven")

# draw the maps
state_plot <- map_us_fertilizer(data = us_fertilizer_county, Year = Year, Nutrient = Nutrient,
                             Farm_Type = Farm_Type, Input_Type = Input_Type, State = carolinas,
                             County = county,  viridis_palette = "inferno", level = level)+
  # add title
    ggtitle(paste(Nutrient, " from ", Input_Type, " input to ", Farm_Type, " in the year of ",Year,
                     " at ", level, " level\nin southeast North Carolina",sep = ""))

state_plot 


wenlong-liu/ggfertilizer documentation built on May 28, 2019, 8:43 a.m.