-
Notifications
You must be signed in to change notification settings - Fork 4
/
readme.rmd
170 lines (131 loc) · 7.51 KB
/
readme.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
---
output: rmarkdown::github_document
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
# usfertilizer <img src="https://raw.githubusercontent.com/wenlong-liu/usfertilizer_sticker/master/usfertilizer.png" align="right" height = "120"/>
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/usfertilizer)](https://cran.r-project.org/package=usfertilizer)
[![Travis-CI Build Status](https://travis-ci.org/wenlong-liu/usfertilizer.svg?branch=master)](https://travis-ci.org/wenlong-liu/usfertilizer)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/wenlong-liu/usfertilizer?branch=master&svg=true)](https://ci.appveyor.com/project/wenlong-liu/usfertilizer)
[![](https://cranlogs.r-pkg.org/badges/usfertilizer)](https://cran.r-project.org/package=usfertilizer)
[![metacran downloads](http://cranlogs.r-pkg.org/badges/grand-total/usfertilizer?color=ff69b4)](https://cran.r-project.org/package=usfertilizer)
[![DOI](https://zenodo.org/badge/123758879.svg)](https://zenodo.org/badge/latestdoi/123758879)
## County-lelel nutrients data from 1945 to 2012 in USA
Usfertilizer summarized the estimated county level data from USGS of USA and provided a clean version using Tidyverse.
Please note that USGS does not endorse this package. Also data from 1986 is not available for now.
## Introduction of data sources and availability
The data used in this package were original compiled and processed by United States Geographic Services (USGS). The fertilizer data include the application in both farms and non-farms for 1945 through 2012. The folks in USGS utilized the sales data of commercial fertilizer each state or county from the Association of American Plant Food Control Officials (AAPFCO) commercial fertilizer sales data. State estimates were then allocated to the county-level using fertilizer expenditure from the Census of Agriculture as county weights for farm fertilizer, and effective population density as county weights for nonfarm fertilizer. The data sources and other further information are availalbe in Table below.
|Dataset name | Temporal coverage| Source| Website | Comments |
|-------------------|:-------------:|:---------:| ---------|:--------------------|
|Fertilizer data before 1985 | 1945 - 1985 | USGS | [Link](https://pubs.er.usgs.gov/publication/ofr90130) |Only has farm data.|
|Fertilizer data after 1986 | 1986 - 2012 | USGS | [Link](https://www.sciencebase.gov/catalog/item/5851b2d1e4b0f99207c4f238) |Published in 2017.|
|County background data | 2010 | US Census| [Link](https://www.census.gov/geo/maps-data/data/gazetteer2010.html) |Assume descriptors of counties do not change.|
|Manure data before 1997 | 1982 - 1997 | USGS | [Link](https://pubs.usgs.gov/sir/2006/5012/) | Manual data into farm every five years |
|Manure data in 2002 | 2002 | USGS | [Link](https://pubs.usgs.gov/of/2013/1065/) | Published in 2013 |
|Manure data in 2007 and 2012| 2007 & 2012 | USGS | [Link](https://www.sciencebase.gov/catalog/item/581ced4ee4b08da350d52303) | Published in 2017 |
## Installation
Install the stable version via CRAN, just run:
```{r, eval= FALSE}
install.packages("usfertilizer")
```
You can also install the package via my Github Repository.
```{r, eval=FALSE}
# install.package("devtools") #In case you have not installed it.
devtools::install_github("wenlong-liu/usfertilizer")
```
## Get started
### Import data and related libraries
```{r, message=FALSE, warning=FALSE}
require(usfertilizer)
require(tidyverse)
data("us_fertilizer_county")
```
### Summary of the dataset
The dataset, named by us_fertilizer_county, contains `r length(us_fertilizer_county$FIPS)` observations and 11 variables. Details are available by using `?us_fertilizer_county`.
```{r}
glimpse(us_fertilizer_county)
```
## Examples
### Example 1: Find out the top 10 counties with most nitrogen appliation in 2008.
```{r}
# plot the top 10 nitrogen application in year 2008.
# Reorder to make the plot more cleanner.
year_plot = 2008
us_fertilizer_county %>%
filter(Nutrient == "N" & Year == year_plot & Input.Type == "Fertilizer" ) %>%
top_n(10, Quantity) %>%
ggplot(aes(x=reorder(paste(County,State, sep = ","), Quantity), Quantity, fill = Quantity))+
scale_fill_gradient(low = "blue", high = "darkblue")+
geom_col()+
ggtitle(paste("Top 10 counties with most fertilizer application in the year of", year_plot)) +
scale_y_continuous(name = "Nitrogen from commecial fertilization (kg)")+
scale_x_discrete(name = "Counties")+
coord_flip()+
theme_bw()
```
### Example 2: Find out the top 10 states with most nitrogen appliation in 1980.
```{r}
# plot the top 10 states with P application in year 1980.
# Reorder to make the plot more cleanner.
year_plot = 1980
us_fertilizer_county %>%
filter(Nutrient == "P" & Year == 1980 & Input.Type == "Fertilizer") %>%
group_by(State) %>%
summarise(p_application = sum(Quantity)) %>%
as.data.frame() %>%
top_n(10, p_application) %>%
ggplot(aes(x=reorder(State, p_application), p_application))+
scale_fill_gradient(low = "blue", high = "darkblue")+
geom_col()+
ggtitle(paste("Top 10 States with most Phosphrus application in the year of", year_plot)) +
scale_y_continuous(name = "Phosphrus from commecial fertilizer (kg)")+
scale_x_discrete(name = "States")+
theme_bw()+
coord_flip()
```
### Example 3: Plot the N and P input into farms for NC and SC from 1945 to 2010
```{r, message=F, warning=F}
year_plot = seq(1945, 2010, 1)
states = c("NC","SC")
us_fertilizer_county %>%
filter(State %in% states & Year %in% year_plot &
Farm.Type == "farm" & Input.Type == "Fertilizer") %>%
group_by(State, Year, Nutrient) %>%
summarise(Quantity = sum(Quantity, na.rm = T)) %>%
ggplot(aes(x = as.numeric(Year), y = Quantity, color=State)) +
geom_point() +
geom_line()+
scale_x_continuous(name = "Year")+
scale_y_continuous(name = "Nutrient input quantity (kg)")+
facet_wrap(~Nutrient, scales = "free", ncol = 2)+
ggtitle("Estimated nutrient inputs into arable lands by commercial fertilizer\nfrom 1945 to 2010 in Carolinas")+
theme_bw()
```
### Example 4: Plot the N input into farms from fertilizer and manure for NC and SC from 1945 to 2012
```{r}
us_fertilizer_county %>%
filter(State %in% states & Year %in% year_plot &
Farm.Type == "farm" & Nutrient == "N") %>%
group_by(State, Year, Input.Type) %>%
summarise(Quantity = sum(Quantity, na.rm = T)) %>%
ggplot(aes(x = as.numeric(Year), y = Quantity, color=Input.Type)) +
geom_point() +
geom_line()+
scale_x_continuous(name = "Year")+
scale_y_continuous(name = "Nutrient input quantity (kg)")+
facet_wrap(~State, scales = "free", ncol = 2)+
ggtitle("Estimated nutrient inputs into arable lands by commercial fertilizer and manure\nfrom 1945 to 2012 in Carolinas")+
theme_bw()
```
## Comments and Questions.
If you have any problems or questions, feel free to open an issue [here](https://github.com/wenlong-liu/usfertilizer/issues).
## Lisence
[GPL](https://github.com/wenlong-liu/usfertilizer/blob/master/lisence.txt)
## Code of conduct
Please note that this project is released with a [Contributor Code of Conduct](https://github.com/wenlong-liu/usfertilizer/blob/master/CONDUCT.md). By participating in this project you agree to abide by its terms.
## Preferred citation
Wenlong Liu (2018). usfertilizer: County-Level Estimates of Fertilizer Application in USA. R package version 0.1.5. https://CRAN.R-project.org/package=usfertilizer. DOI:10.5281/zenodo.1292843