ggfertilizer--- title: "Visualize fertilizer data in U.S. maps" author: "Wenlong Liu" date: "r Sys.Date()" output: rmarkdown::html_vignette

vignette: > %\VignetteIndexEntry{Visualize fertilizer data in U.S. maps} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8}


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

Plotting data in US maps.

Import libraries and dataset.

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

Maps at county level.

# Initilize input parameters.
Year = 2001
Nutrient = "N"
Farm_Type = "farm"
Input_Type = "fertilizer"
level  = "county"

# draw the map
us_plot <- map_us_fertilizer(data = data, Year = Year, Nutrient = Nutrient,
                             Farm_Type = Farm_Type, Input_Type = Input_Type,
                             viridis_palette = "inferno", level = level) +
  ggtitle(paste(Nutrient, " from ", Input_Type, " input to ", Farm_Type, " in the year of ",Year,
                     " at ", level, " level",sep = ""))
us_plot

Maps at state level.

level = "state"
Year = 1997
Input_Type = "manure"
us_plot <- map_us_fertilizer(data = data, Year = Year, Nutrient = Nutrient,
                             Farm_Type = Farm_Type, Input_Type = Input_Type,
                             viridis_palette = "inferno", level = level) +
  ggtitle(paste(Nutrient,  " from ", Input_Type, " input to ", Farm_Type, " in the year of ",Year,
                     " at ", level, " level",sep = ""))
us_plot

Chanage projection system

We can also change the projection system of the map to "albers" projection.

us_plot +
  ggtitle(paste(Nutrient,  " from ", Input_Type, " input to ", Farm_Type, " in the year of ",Year,
                     " at ", level, " level",sep = ""))+
  coord_map("albers",lat0=39, lat1=45)

Maps with facets.

Year = c(1945, 1975, 2005)
facet = "Year"
nutrient = "N"
Input_Type = "fertilizer"
level = "county"
us_plot <- map_us_fertilizer(data = data, Year = Year, Nutrient = Nutrient,
                             Farm_Type = Farm_Type, Input_Type = Input_Type,
                             viridis_palette = "inferno", level = level,
                             facet = facet) +
  ggtitle(paste(Nutrient," input "," from ", Input_Type,  " to ", Farm_Type, 
                     " at ", level, " level",sep = ""))

us_plot


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