/
State_fertilizer_maps.Rmd
119 lines (98 loc) · 3.66 KB
/
State_fertilizer_maps.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
---
title: "Visualize fertilizer data in states and counties "
author: "Wenlong Liu"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Visualize fertilizer data in in states and counties}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.width = 6,
fig.height = 4
)
```
## Import libraries and data
```{r}
require(ggfertilizer)
require(ggplot2)
require(ggsn)
data("us_fertilizer_county")
```
## Plot P input from manure maps for carolinas
```{r}
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](https://github.com/oswaldosantos/ggsn).
```{r}
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
```{r}
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.
```{r}
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
```