Skip to content

Commit

Permalink
usfertilizer 0.1.4
Browse files Browse the repository at this point in the history
* Added manure data from 1982 to 2012 (every five years).
* Update the column names: Fertilizer -> Nutrient.
* Added another column: Input.Type to indicate the nutrient input type.
* Update readme and related articles.
* Fixed the failed build of vignettes.
  • Loading branch information
wenlong-liu committed Mar 30, 2018
1 parent faf5567 commit 29f25e5
Show file tree
Hide file tree
Showing 48 changed files with 13,805 additions and 352 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
^\.travis\.yml$
.Rprofile
inst/db
inst/doc
man-roxygen
demo/pandas
^\.httr-oauth$
Expand Down
12 changes: 6 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Package: usfertilizer
Type: Package
Title: County-Level Estimates of Fertilizer Application in US
Version: 0.1.3
Version: 0.1.4
Authors@R: c(
person("Wenlong", "Liu", role = c("aut","cre"),
email = 'wliu14@ncsu.edu')
)
Maintainer: Wenlong Liu <wliu14@ncsu.edu>
Description: Compiled and cleaned the county-level estimates of fertilizer,
nitrogen and phosphorus, from 1945 to 2012. The dataset were originally
generated by USGS based on the sales data of commercial fertilizer.
See <https://www.sciencebase.gov/catalog/item/5851b2d1e4b0f99207c4f238/> for details.
nitrogen and phosphorus, from 1945 to 2012. The commercial fertilizer data were originally
generated by USGS based on the sales data of commercial fertilizer. The manure data were estimated
based on county-level population data of livestock, poultry, and other animals.
See the user manual for detailed data sources and cleaning methods.
'usfertilizer' utilized the tidyverse to clean the original data and provide
user-friendly dataframe. Please note that USGS does not endorse this package and this package
does not include manure data. Also data from 1986 is not available for now.
user-friendly dataframe. Please note that USGS does not endorse this package. Also data from 1986 is not available for now.
License: GPL
URL: https://github.com/wenlong-liu/usfertilizer
BugReports: https://github.com/wenlong-liu/usfertilizer/issues
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@
* Added a license file and code of conduct.
* Enable website for project using pkgdown.

# usfertilizer 0.1.4

* Added manure data from 1982 to 2012 (every five years).
* Update the column names: Fertilizer -> Nutrient.
* Added another column: Input.Type to indicate the nutrient input type.
* Update readme and related articles.
* Fixed the failed build of vignettes.

5 changes: 3 additions & 2 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' us_fertilizer_county
#'
#' This is data adapted from the county-level estimates of fertilizer nitrogen and phosphorus based on
#' commacial sales from 1945 to 2012. Please visit [here](https://www.sciencebase.gov/catalog/item/5851b2d1e4b0f99207c4f238)
#' commercial sales from 1945 to 2012. Please visit [here](https://www.sciencebase.gov/catalog/item/5851b2d1e4b0f99207c4f238)
#' for more details.
#'
#' @format A data frame with 582012rows and 11 variables:
Expand All @@ -15,8 +15,9 @@
#' \item{INTPTLONG}{The longitude of centriod in each county, e.g. -86.64449}
#' \item{Quantity}{The quantity of fertilizeation as N or P, e.g. kg N or kg P}
#' \item{Year}{The year of estimated data, e.g. 1994}
#' \item{Fertilizer}{The fertilizer type, e.g. N or P}
#' \item{Nutrient}{The fertilizer type, e.g. N or P}
#' \item{Farm.Type}{The land use type of fertilizer, e.g. farm and nonfarm}
#' \item{Input.Type}{The input type of nutrient, e.g. Fertilizer or Manure}
#' ...
#' }
#' @examples
Expand Down
8 changes: 0 additions & 8 deletions R/usfertilizer.R

This file was deleted.

47 changes: 34 additions & 13 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ usfertilizer
================

<!--[![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)
[![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)-->

County-lelel nutrients data from 1945 to 2012
Expand Down Expand Up @@ -41,12 +41,12 @@ data("us_fertilizer_county")

### Summary of the dataset

The dataset, named by us\_fertilizer\_county, contains 582012 observations and 11 variables. Details are available by using `?us_fertilizer_county`.
The dataset, named by us\_fertilizer\_county, contains 625580 observations and 11 variables. Details are available by using `?us_fertilizer_county`.

``` r
glimpse(us_fertilizer_county)
#> Observations: 582,012
#> Variables: 11
#> Observations: 625,580
#> Variables: 12
#> $ FIPS <chr> "01001", "01003", "01005", "01007", "01009", "01011...
#> $ State <chr> "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL...
#> $ County <chr> "Autauga", "Baldwin", "Barbour", "Bibb", "Blount", ...
Expand All @@ -56,8 +56,9 @@ glimpse(us_fertilizer_county)
#> $ INTPTLONG <dbl> -86.64449, -87.74607, -85.40546, -87.12715, -86.567...
#> $ Quantity <dbl> 1580225, 6524369, 2412372, 304592, 1825118, 767573,...
#> $ Year <chr> "1987", "1987", "1987", "1987", "1987", "1987", "19...
#> $ Fertilizer <chr> "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "...
#> $ Nutrient <chr> "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "...
#> $ Farm.Type <chr> "farm", "farm", "farm", "farm", "farm", "farm", "fa...
#> $ Input.Type <chr> "Fertilizer", "Fertilizer", "Fertilizer", "Fertiliz...
```

Examples
Expand All @@ -70,7 +71,7 @@ Examples
# Reorder to make the plot more cleanner.
year_plot = 2008
us_fertilizer_county %>%
filter(Fertilizer == "N" & Year == year_plot) %>%
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")+
Expand All @@ -91,7 +92,7 @@ us_fertilizer_county %>%
# Reorder to make the plot more cleanner.
year_plot = 1980
us_fertilizer_county %>%
filter(Fertilizer == "P" & Year == 1980) %>%
filter(Nutrient == "P" & Year == 1980 & Input.Type == "Fertilizer") %>%
group_by(State) %>%
summarise(p_application = sum(Quantity)) %>%
as.data.frame() %>%
Expand All @@ -100,7 +101,7 @@ us_fertilizer_county %>%
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 fertilization (kg)")+
scale_y_continuous(name = "Phosphrus from commecial fertilizer (kg)")+
scale_x_discrete(name = "States")+
theme_bw()+
coord_flip()
Expand All @@ -116,21 +117,41 @@ states = c("NC","SC")

us_fertilizer_county %>%
filter(State %in% states & Year %in% year_plot &
Farm.Type == "farm") %>%
group_by(State, Year, Fertilizer) %>%
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(~Fertilizer, scales = "free", ncol = 2)+
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()
```

![](readme_files/figure-markdown_github/unnamed-chunk-7-1.png)

### 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()
```

![](readme_files/figure-markdown_github/unnamed-chunk-8-1.png)

Comments and Questions.
-----------------------

Expand All @@ -139,9 +160,9 @@ If you have any problems or questions, feel free to open an issue [here](https:/
Lisence
-------

[GPL](https://github.com/wenlong-liu/usfertilizer/lisence.txt)
[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/CONDUCT.md). By participating in this project you agree to abide by its terms.
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.
Loading

0 comments on commit 29f25e5

Please sign in to comment.