Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
updatded man files for new roxygen2 version, and fixed climate_map fx…
Browse files Browse the repository at this point in the history
…n to not use fill when only 1 thing
  • Loading branch information
sckott committed Mar 30, 2015
1 parent ef33bf1 commit 32e3923
Show file tree
Hide file tree
Showing 37 changed files with 251 additions and 372 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ Makefile
.gitignore
README.Rmd
^appveyor\.yml$
^.*\.Rproj$
^\.Rproj\.user$
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Generated by roxygen2 (4.1.0): do not edit by hand

export(climate_map)
export(create_map_df)
export(get_data_recursive)
Expand Down
27 changes: 18 additions & 9 deletions R/climate_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
#'@return Either a ggplot2 map or a dataframe depending on the parameter return_map
#'@examples \dontrun{
#' #Set the kmlpath option
#' options(kmlpath = "/Users/edmundhart/kmltemp")
#' options(kmlpath = "~/kmltemp2")
#' ##Here we use a list basins for Africa
#' af_basin <- create_map_df(Africa_basin)
#' af_basin_dat <- get_ensemble_temp(Africa_basin,"annualanom",2080,2100)
#' ## Subset data to just one scenario, and one percentile
#' af_basin_dat <- subset(af_basin_dat,af_basin_dat$scenario == "a2")
#' af_basin_dat <- subset(af_basin_dat,af_basin_dat$percentile == 50)
#' af_map <- climate_map(af_basin,af_basin_dat,return_map = T)
#' af_map <- climate_map(map_df = af_basin, data_df = af_basin_dat, return_map = TRUE)
#' af_map + scale_fill_continuous("Temperature \n anomaly",low="yellow",high = "red") + theme_bw()
#'
#'
#'}
#'
#'@export
Expand All @@ -30,19 +30,28 @@ climate_map <- function(map_df, data_df, return_map = TRUE){
## Order data for easy matching
data_df <- data_df[order(data_df$locator),]
map_df <- map_df[order(map_df$ID),]

ids <- unique(map_df$ID)
data_vec <- vector()
for(i in 1:length(ids)){
data_vec <- c(data_vec,rep(data_df$data[i],sum(map_df$ID==ids[i])))
}

if(is.list(data_vec)){
data_vec <- unlist(data_vec)
}

map_df$data <- data_vec
map <- ggplot(map_df, aes(x=long, y=lat,group=group,fill=data))+ geom_polygon()
if(return_map == TRUE){return(map)
} else {return(map_df)}
if(length(unique(map_df$data)) == 1) {
map <- ggplot(map_df, aes(x = long, y = lat, group = group)) +
geom_polygon()
} else {
map <- ggplot(map_df, aes(x = long, y = lat, group = group, fill = data)) +
geom_polygon()
}
if (return_map) {
return(map)
} else {
return(map_df)
}
}
2 changes: 2 additions & 0 deletions man/Africa_basin.Rd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/rWBclimate-package.r
\docType{data}
\name{Africa_basin}
\alias{Africa_basin}
Expand Down
2 changes: 2 additions & 0 deletions man/Africa_country.Rd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/rWBclimate-package.r
\docType{data}
\name{Africa_country}
\alias{Africa_country}
Expand Down
2 changes: 2 additions & 0 deletions man/Asia_basin.Rd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/rWBclimate-package.r
\docType{data}
\name{Asia_basin}
\alias{Asia_basin}
Expand Down
2 changes: 2 additions & 0 deletions man/Asia_country.Rd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/rWBclimate-package.r
\docType{data}
\name{Asia_country}
\alias{Asia_country}
Expand Down
2 changes: 2 additions & 0 deletions man/Eur_basin.Rd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/rWBclimate-package.r
\docType{data}
\name{Eur_basin}
\alias{Eur_basin}
Expand Down
2 changes: 2 additions & 0 deletions man/Eur_country.Rd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/rWBclimate-package.r
\docType{data}
\name{Eur_country}
\alias{Eur_country}
Expand Down
2 changes: 2 additions & 0 deletions man/NoAm_basin.Rd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/rWBclimate-package.r
\docType{data}
\name{NoAm_basin}
\alias{NoAm_basin}
Expand Down
2 changes: 2 additions & 0 deletions man/NoAm_country.Rd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/rWBclimate-package.r
\docType{data}
\name{NoAm_country}
\alias{NoAm_country}
Expand Down
2 changes: 2 additions & 0 deletions man/Oceana_basin.Rd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/rWBclimate-package.r
\docType{data}
\name{Oceana_basin}
\alias{Oceana_basin}
Expand Down
2 changes: 2 additions & 0 deletions man/Oceana_country.Rd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/rWBclimate-package.r
\docType{data}
\name{Oceana_country}
\alias{Oceana_country}
Expand Down
2 changes: 2 additions & 0 deletions man/SoAm_basin.Rd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/rWBclimate-package.r
\docType{data}
\name{SoAm_basin}
\alias{SoAm_basin}
Expand Down
2 changes: 2 additions & 0 deletions man/SoAm_country.Rd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/rWBclimate-package.r
\docType{data}
\name{SoAm_country}
\alias{SoAm_country}
Expand Down
9 changes: 4 additions & 5 deletions man/check_ISO_code.Rd
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/check_ISO_code.R
\name{check_ISO_code}
\alias{check_ISO_code}
\title{check country codes}
\usage{
check_ISO_code(iso)
}
\arguments{
\item{iso}{The 3 letter country code based on ISO3
Country abbreviations
(http://unstats.un.org/unsd/methods/m49/m49alpha.htm)}
\item{iso}{The 3 letter country code based on ISO3 Country abbreviations (http://unstats.un.org/unsd/methods/m49/m49alpha.htm)}
}
\value{
TRUE if a valid code, otherwise an error is returned
}
\description{
Checks if the country code entered is a valid country code
that data exists for
Checks if the country code entered is a valid country code that data exists for
}
\examples{
\dontrun{
Expand Down
10 changes: 4 additions & 6 deletions man/check_locator.Rd
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/check_locator.R
\name{check_locator}
\alias{check_locator}
\title{Checks for what kind of locator a user input}
\usage{
check_locator(locator)
}
\arguments{
\item{locator}{The ISO3 country code that you want data
about.
(http://unstats.un.org/unsd/methods/m49/m49alpha.htm) or
the basin ID [1-468]}
\item{locator}{The ISO3 country code that you want data about. (http://unstats.un.org/unsd/methods/m49/m49alpha.htm) or the basin ID [1-468]}
}
\value{
geo_ref a string indicating what kind of geography to use
in the api
geo_ref a string indicating what kind of geography to use in the api
}
\description{
Checks for what kind of locator a user input
Expand Down
24 changes: 9 additions & 15 deletions man/climate_map.Rd
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/climate_map.R
\name{climate_map}
\alias{climate_map}
\title{Map climate data}
\usage{
climate_map(map_df, data_df, return_map = TRUE)
}
\arguments{
\item{map_df}{a map dataframe generated from
create_map_df()}
\item{map_df}{a map dataframe generated from create_map_df()}

\item{data_df}{a climate dataframe with one piece of data
to be mapped to each unique spatial polygon.}
\item{data_df}{a climate dataframe with one piece of data to be mapped to each unique spatial polygon.}

\item{return_map}{True returns a ggplot2 object, False
returns a dataframe where data items are matched to their
polygon that you can plot later on.}
\item{return_map}{True returns a ggplot2 object, False returns a dataframe where data items are matched to their polygon that you can plot later on.}
}
\value{
Either a ggplot2 map or a dataframe depending on the
parameter return_map
Either a ggplot2 map or a dataframe depending on the parameter return_map
}
\description{
Create maps of climate data. It requires two data inputs,
a map dataframe, and a climate dataframe. The climate data
must have one data point per spatial mapping point,e.g. 1
data point per country or basin being mapped.
Create maps of climate data. It requires two data inputs, a map dataframe, and a climate dataframe. The climate data must have one data point per spatial mapping point,e.g. 1 data point per country or basin being mapped.
}
\examples{
\dontrun{
#Set the kmlpath option
options(kmlpath = "/Users/edmundhart/kmltemp")
options(kmlpath = "~/kmltemp2")
##Here we use a list basins for Africa
af_basin <- create_map_df(Africa_basin)
af_basin_dat <- get_ensemble_temp(Africa_basin,"annualanom",2080,2100)
## Subset data to just one scenario, and one percentile
af_basin_dat <- subset(af_basin_dat,af_basin_dat$scenario == "a2")
af_basin_dat <- subset(af_basin_dat,af_basin_dat$percentile == 50)
af_map <- climate_map(af_basin,af_basin_dat,return_map = T)
af_map <- climate_map(map_df = af_basin, data_df = af_basin_dat, return_map = TRUE)
af_map + scale_fill_continuous("Temperature \\n anomaly",low="yellow",high = "red") + theme_bw()

}
Expand Down
2 changes: 2 additions & 0 deletions man/codes.Rd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/rWBclimate-package.r
\docType{data}
\name{codes}
\alias{codes}
Expand Down
22 changes: 6 additions & 16 deletions man/create_map_df.Rd
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/create_map_df.R
\name{create_map_df}
\alias{create_map_df}
\title{Create mapable dataframe}
\usage{
create_map_df(locator)
}
\arguments{
\item{locator}{The a vector of ISO3 country code's that
you want data about.
(http://unstats.un.org/unsd/methods/m49/m49alpha.htm) or
the basin ID's [1-468]
(http://data.worldbank.org/sites/default/files/climate_data_api_basins.pdf)}
\item{locator}{The a vector of ISO3 country code's that you want data about. (http://unstats.un.org/unsd/methods/m49/m49alpha.htm) or the basin ID's [1-468] (http://data.worldbank.org/sites/default/files/climate_data_api_basins.pdf)}
}
\description{
A function that will download maps for a vector of basins
or country codes and return a data frame that has the kml
output processed such that it can be plotted with ggplot2
and other mapping functions:
A function that will download maps for a vector of basins or country codes and return a data frame that has the kml output processed such that it can be plotted with ggplot2 and other mapping functions:
}
\details{
kml files can be quite large (100k-600k per country) making
downloading them every time you want to make a map time
consuming. To reduce this time it's easiest to download
kml files and store them. To set the directory use a line
like this: \code{options(kmlpath="/Users/emh/kmltemp")} The
option must be called "kmlpath". These files will be
persistent until you delete them.
kml files can be quite large (100k-600k per country) making downloading them every time you want to make a map time consuming. To
reduce this time it's easiest to download kml files and store them. To set the directory use a line like this: \code{options(kmlpath="/Users/emh/kmltemp")} The option must be called "kmlpath". These files will be persistent until you delete them.
}
\examples{
\dontrun{
Expand Down
15 changes: 7 additions & 8 deletions man/date_correct.Rd
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/date_correct.R
\name{date_correct}
\alias{date_correct}
\title{correct data values}
\usage{
date_correct(start, end)
}
\arguments{
\item{start}{The start year}
\item{start}{The start year}

\item{end}{The end year}
\item{end}{The end year}
}
\value{
a 2xM matrix where M in the number of periods in the data
api
a 2xM matrix where M in the number of periods in the data api
}
\description{
Round start and end dates to conform with data api
standards. See api documentation
(http://data.worldbank.org/developers/climate-data-api) for
full details
Round start and end dates to conform with data api standards. See api documentation (http://data.worldbank.org/developers/climate-data-api)
for full details
}
\examples{
\dontrun{
Expand Down
20 changes: 6 additions & 14 deletions man/download_kml.Rd
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/download_kml.R
\name{download_kml}
\alias{download_kml}
\title{Download kml files}
\usage{
download_kml(locator)
}
\arguments{
\item{locator}{The a vector of ISO3 country code's that
you want data about.
(http://unstats.un.org/unsd/methods/m49/m49alpha.htm) or
the basin ID's [1-468]
(http://data.worldbank.org/sites/default/files/climate_data_api_basins.pdf)}
\item{locator}{The a vector of ISO3 country code's that you want data about. (http://unstats.un.org/unsd/methods/m49/m49alpha.htm) or the basin ID's [1-468] (http://data.worldbank.org/sites/default/files/climate_data_api_basins.pdf)}
}
\description{
Downloads map data from in kml format and writes it to a
temporary directory. You must specify a temporary
directory to write files to in your options.
Downloads map data from in kml format and writes it to a temporary directory. You must specify a temporary directory to write files to in your options.
}
\details{
kml files can be quite large making downloading them every
time you want to make a map time consuming. To reduce this
time it's easiest to download kml files and store them. To
set the directory use a line like this:
\code{options(kmlpath="/Users/emh/kmltemp")} The option
must be called "kmlpath".
kml files can be quite large making downloading them every time you want to make a map time consuming. To
reduce this time it's easiest to download kml files and store them. To set the directory use a line like this: \code{options(kmlpath="/Users/emh/kmltemp")} The option must be called "kmlpath".
}
31 changes: 10 additions & 21 deletions man/get_climate_data.Rd
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/get_climate_data.R
\name{get_climate_data}
\alias{get_climate_data}
\title{get_climate_data}
\usage{
get_climate_data(locator, geo_type, type, cvar, start, end)
}
\arguments{
\item{locator}{The ISO3 country code that you want data
about.
(http://unstats.un.org/unsd/methods/m49/m49alpha.htm) or
the basin ID [1-468]}
\item{locator}{The ISO3 country code that you want data about. (http://unstats.un.org/unsd/methods/m49/m49alpha.htm) or the basin ID [1-468]}

\item{geo_type}{basin or country depending on the locator
type}
\item{geo_type}{basin or country depending on the locator type}

\item{type}{the type of data you want "mavg" for monthly
averages, "annualavg"}
\item{type}{the type of data you want "mavg" for monthly averages, "annualavg"}

\item{cvar}{The variable you're interested in. "pr" for
precipitation, "tas" for temperature in celcius.}
\item{cvar}{The variable you're interested in. "pr" for precipitation, "tas" for temperature in celcius.}
\item{start}{The starting year you want data for, can be
in the past or the future. Must conform to the periods
outlined in the world bank API. If given values don't
conform to dates, the fuction will automatically round
them.}
\item{start}{The starting year you want data for, can be in the past or the future. Must conform to the periods outlined in the world bank API. If given values don't conform to dates, the fuction will automatically round them.}

\item{end}{The ending year you want data for, can be in
the past or the future. Similar to the start date, dates
will be rounded to the nearest end dat.}
\item{end}{The ending year you want data for, can be in the past or the future. Similar to the start date, dates will be rounded to the nearest end dat.}
}
\description{
Download monthly average climate data from the world bank
climate data api. Ideally you'll want to use the wrapper
functions that call this.
Download monthly average climate data from the world bank climate
data api. Ideally you'll want to use the wrapper functions that call this.
}
Loading

0 comments on commit 32e3923

Please sign in to comment.