#' Make nutrient trends map function
#'
#' This function allows you to plot nutrient trends data on ggplot maps.
#'
#' You can either use included nutrient data or supply your own point data in shapefile format.
#' Similarly you can either use the default included coastline of New Zealand or supply your own
#' polygon in shapefile format.
#'
#' Included data:
#' \itemize{
#' \item tp = Total phosphorus
#' \item drp = Dissovled reactive phosphorus
#' \item nn = Nitrate nitrogen
#' \item tn = Total nitrogen
#' \item an = ammoniacal nitrogen
#' }
#' @param pt_dat Expects input of a point shapefile, in either WGS84 or NZTM.
#' @param coastline Expects input of a coastline shapefile, defaults to NZ topo coastline.
#' @keywords ggplot NZ maps
#' @examples
#' plot.trends(tp)
#' plot.trends(drp) + ggplot2::labs(title = "Dissolved reactive phosphorus")
#' @import ggplot2
#' @import RColorBrewer
#' @import rgdal
#' @import sp
#' @import mapproj
#' @export
plot.trends <- function(pt_dat, coastline = spatinz::coastline){
an <- spatinz::an
tn <- spatinz::tn
nn <- spatinz::nn
drp <- spatinz::drp
tp <- spatinz::tp
coastline_dat <- fortify(coastline) # makes polygon shapefiles able to be read by ggplot
wgs84 = '+proj=longlat +datum=WGS84' # define wgs84 information
pt_dat <- spTransform(pt_dat, CRS(wgs84)) # reproject to wgs84
pt_dat <- data.frame(pt_dat) # converts point data to ggplot readable
### setup consistent colour scale
myColours <- brewer.pal(7,"Set1") # choose colours
names(myColours) <- c("CertainDec", "Insufficient", "CertainInc", "ImportantDec",
"ImportantInc", "NotImportantDec", "NotImportantInc") # define levels
colourScale <- scale_colour_manual(values = myColours) # create the manual scale
ggplot() +
geom_path(data = coastline_dat, aes(long, lat, group = group), size = 0.25) +
geom_point(data = pt_dat, aes(x = coords.x1, y = coords.x2, colour = ImportFlow), size = 2) +
colourScale +
theme_void() +
coord_map()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.