Skip to content

Commit 965e512

Browse files
author
cas
committed
v1.0.2 rename function names to avoid problems with S3 methods
1 parent 2db8cfe commit 965e512

25 files changed

+279
-279
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: plotFun
22
Type: Package
33
Title: Helper functions for plotting data
4-
Version: 1.0.1
4+
Version: 1.0.2
55
Date: 2019-01-15
66
Author: A. Casanueva
77
Maintainer: A.Casanueva <ana.casanueva@meteoswiss.ch>

NAMESPACE

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
export(data.agg)
4-
export(plot.Grid)
5-
export(plot.Stn)
6-
export(plot.TimeSeries)
7-
export(plot.heat)
8-
export(plot.kde2d.hist)
3+
export(data_agg)
4+
export(plotFun.grid)
5+
export(plotFun.heat)
6+
export(plotFun.kde2d.hist)
7+
export(plotFun.stn)
8+
export(plotFun.ts)
99
import(HeatStress)
1010
import(MASS)
1111
import(RColorBrewer)

NEWS

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
* Changes in v.1.0.1
1+
* Changes in v1.0.2
2+
3+
Change function names to avoid S3 methods.
4+
5+
* Changes in v1.0.1
26

37
Package ready to use

R/data.agg.R renamed to R/data_agg.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
#' data.day <- array(runif(length(dates.day)*2, -5, 30), dim=c(length(dates.day),2))
2020
#' data.hour <- rnorm(length(dates.hour), mean=15, sd=2)
2121
#' # Aggregate from daily to annual
22-
#' data.agg(data.day, dates.day, agg="Y", aggFun="mean")
22+
#' data_agg(data.day, dates.day, agg="Y", aggFun="mean")
2323
#' # Aggregate from daily to monthly
24-
#' data.agg(data.day, dates.day, agg="M", aggFun="max")
24+
#' data_agg(data.day, dates.day, agg="M", aggFun="max")
2525
#' # Aggregate from daily to seasonal
26-
#' data.agg(data.day, dates.day, agg="S", aggFun="min")
26+
#' data_agg(data.day, dates.day, agg="S", aggFun="min")
2727
#' # Aggregate from hourly to daily
28-
#' data.agg(data.hour, dates.hour, agg="D", aggFun="mean")
28+
#' data_agg(data.hour, dates.hour, agg="D", aggFun="mean")
2929
#' }
3030

3131

32-
data.agg <- function(data, dates, agg=NULL, aggFun="mean", input.mch=FALSE){
32+
data_agg <- function(data, dates, agg=NULL, aggFun="mean", input.mch=FALSE){
3333

3434

3535
data <- as.matrix(data) # to avoid problems with 1 station (vector)
@@ -190,4 +190,4 @@ data.agg <- function(data, dates, agg=NULL, aggFun="mean", input.mch=FALSE){
190190
res <- list(data.agg=df, dates.agg=dates.agg, agg= agg, aggFun=aggFun)
191191
return(res)
192192

193-
} # end data.agg
193+
} # end data_agg

R/plotFun.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
#' The following plotting functions are implemented:
1212
#' \itemize{
1313
#'
14-
#' \item \code{plot.Stn}: Plot a map of stations.
15-
#' \item \code{plot.Grid}: Plot a map of a regular grid.
16-
#' \item \code{plot.TimeSeries}: Plot time series with or without temporal aggregation.
17-
#' \item \code{plot.kde2d.hist}: Plot a 2D Kernel density plot with the histograms of the marginal distributions.
18-
#' \item \code{plot.heat}: Plot heat index as a function of the input variables.
14+
#' \item \code{plotFun.stn}: Plot a map of stations.
15+
#' \item \code{plotFun.grid}: Plot a map of a regular grid.
16+
#' \item \code{plotFun.ts}: Plot time series with or without temporal aggregation.
17+
#' \item \code{plotFun.kde2d.hist}: Plot a 2D Kernel density plot with the histograms of the marginal distributions.
18+
#' \item \code{plotFun.heat}: Plot heat index as a function of the input variables.
1919
#'
2020
#'
2121
#' Additional functions:
22-
#' \item \code{data.agg}: Function to obtain temporal aggregations (from hours to days and from days to months, seasons or years).
22+
#' \item \code{data_agg}: Function to obtain temporal aggregations (from hours to days and from days to months, seasons or years).
2323
#' \item \code{sort4plot}: Funtion to sort the data in ascending order before plot.
2424

2525
#' }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#' @author Ana Casanueva (16.02.2017)
1212
#'
1313

14-
plot.colorbar <- function(breaks, palette=palette, unit.text, cex.unit, cex.textcbar) {
14+
plotFun.colorbar <- function(breaks, palette=palette, unit.text, cex.unit, cex.textcbar) {
1515

1616

1717
# noo only write some labels, but all colours!!

R/plot.Grid.R renamed to R/plotFun.grid.R

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#' @param export.format "png" or "pdf" format.
2727
#' @param lon.points vector of longitudes for grid points to be marked in the map.
2828
#' @param lat.points vector of latitudes for grid points to be marked in the map.
29-
#' @export plot.Grid
29+
#' @export plotFun.grid
3030
#' @details Packages classInt and maps needed.
3131
#' @import classInt maps
3232
#' @author Ana Casanueva (24.05.2017)
@@ -36,10 +36,10 @@
3636
#' y <- seq(35,55); n=length(y)
3737
#' tas <- array(runif(n*m*6, -5, 30), dim=c(6,m,n)) # time, lon lat.
3838
#' # Single plot
39-
#' plot.Grid(tas[1,,], lon=x, lat = y, lonLims = c(-10,30), latLims = c(35,65), width.cbar = 0.2,
39+
#' plotFun.grid(tas[1,,], lon=x, lat = y, lonLims = c(-10,30), latLims = c(35,65), width.cbar = 0.2,
4040
#' breaks = seq(10,20), title.main = "Mean Temp.", unit.text = "degC", cex.main=1.5)
4141
#' # Multi-plots
42-
#' plot.Grid(list(tas[1,,], tas[2,,], tas[3,,], tas[4,,], tas[5,,], tas[6,,]),
42+
#' plotFun.grid(list(tas[1,,], tas[2,,], tas[3,,], tas[4,,], tas[5,,], tas[6,,]),
4343
#' lon=x, lat = y, lonLims = c(-10,30), latLims = c(35,65), lattice=c(2,3), width.cbar = 0.1,
4444
#' breaks = seq(10,20), window.height = 8, window.width = 12,
4545
#' title.single = c("Temp1","Temp2","Temp3","Temp4","Temp5","Temp6"), cex.single = 1.3,
@@ -48,7 +48,7 @@
4848

4949

5050

51-
plot.Grid <- function(data, lon, lat, lonLims=c(min(lon),max(lon)), latLims=c(min(lat),max(lat)), lattice=NULL, breaks= NULL, palette=rainbow(10), window.width=8, window.height=6, title.main=NULL, title.single=NULL, unit.text=NULL, cex.main=1, cex.single=1, cex.unit=1, cex.textcbar=1, width.cbar=0.1, disp.warnings=FALSE, export=FALSE, export.format=NULL, export.path=NULL, lon.points=NA, lat.points=NA){
51+
plotFun.grid <- function(data, lon, lat, lonLims=c(min(lon),max(lon)), latLims=c(min(lat),max(lat)), lattice=NULL, breaks= NULL, palette=rainbow(10), window.width=8, window.height=6, title.main=NULL, title.single=NULL, unit.text=NULL, cex.main=1, cex.single=1, cex.unit=1, cex.textcbar=1, width.cbar=0.1, disp.warnings=FALSE, export=FALSE, export.format=NULL, export.path=NULL, lon.points=NA, lat.points=NA){
5252

5353
# Verification checks
5454
try(if(export & is.null(export.format)) stop("Cannot save plot: missing export.format"))
@@ -72,11 +72,11 @@ plot.Grid <- function(data, lon, lat, lonLims=c(min(lon),max(lon)), latLims=c(mi
7272
if(is.null(breaks)) breaks <- set.Breaks(data)
7373

7474
# Plot
75-
plot.Grid1(data, lon, lat, lonLims, latLims, breaks, palette, cex.main, title.main, lon.points=lon.points, lat.points=lat.points)
75+
plotFun.grid1(data, lon, lat, lonLims, latLims, breaks, palette, cex.main, title.main, lon.points=lon.points, lat.points=lat.points)
7676

7777
# Include colorbar
7878
par(mar=c(3,0.6,3,5))
79-
plot.colorbar(breaks, palette, unit.text, cex.unit, cex.textcbar)
79+
plotFun.colorbar(breaks, palette, unit.text, cex.unit, cex.textcbar)
8080

8181
} else{
8282
# Number of real plots to make
@@ -110,7 +110,7 @@ plot.Grid <- function(data, lon, lat, lonLims=c(min(lon),max(lon)), latLims=c(mi
110110

111111
# Plot subplots
112112
for (i in 1:n){
113-
plot.Grid1(data[[i]], lon, lat, lonLims, latLims, breaks, palette, cex.single, title.single[i], lon.points=lon.points, lat.points=lat.points)
113+
plotFun.grid1(data[[i]], lon, lat, lonLims, latLims, breaks, palette, cex.single, title.single[i], lon.points=lon.points, lat.points=lat.points)
114114
}
115115

116116
# Fill with empty plots when necessary (i.e. to fill the matrix)
@@ -124,60 +124,11 @@ plot.Grid <- function(data, lon, lat, lonLims=c(min(lon),max(lon)), latLims=c(mi
124124

125125
# Include colorbar
126126
par(mar=c(3,0.6,3,4))
127-
plot.colorbar(breaks, palette, unit.text, cex.unit, cex.textcbar)
127+
plotFun.colorbar(breaks, palette, unit.text, cex.unit, cex.textcbar)
128128
# Plot title
129129
mtext(title.main, outer = TRUE, cex = cex.main)
130130
}
131131

132132
if (export & !is.null(export.format) & !is.null(export.path)) dev.off()
133133
}
134134

135-
#' Plot grid (single plot).
136-
#'
137-
#' Plot a figure based on a regular grid, for a single plot.
138-
#'
139-
#' @param x matrix to be plotted.
140-
#' @param lon array of longitudes
141-
#' @param lat array of latitudes
142-
#' @param lonLims 2-elemtent vector with the range of longitudes to be plotted. By default all the data is plotted.
143-
#' @param latLims 2-elemtent vector with the range of latitudes to be plotted. By default all the data is plotted.
144-
#' @param breaks vector of values defining the intervals to be used in the colorbar.
145-
#' @param palette character vector with the colors for the plot. They will be interpolated to match the number of intervals defined by breaks.
146-
#' @param title.main character string with the title.
147-
#' @param cex.main numeric value giving the title expansion factor. Default: 1.
148-
#' @param lon.points vector of longitudes for grid points to be marked in the map.
149-
#' @param lat.points vector of latitudes for grid points to be marked in the map.
150-
#'
151-
#' @author Ana Casanueva (16.02.2017)
152-
#'
153-
154-
plot.Grid1 <- function(x, lon, lat, lonLims,latLims, breaks= breaks, palette=palette, cex.main, title.main, lon.points=lon.points, lat.points=lat.points) {
155-
156-
# Plot subregion or not
157-
ind.x <- which(lon >= lonLims[1] & lon <= lonLims[2])
158-
ind.y <- which(lat >= latLims[1] & lat <= latLims[2])
159-
lon <- lon[ind.x]
160-
lat <- lat[ind.y]
161-
x <- x[ind.x, ind.y]
162-
163-
# Number of intervals to plot
164-
lev <- length(breaks)-1;
165-
166-
# Interpolate palette to the number of levels
167-
cols <- colorRampPalette(palette)(lev)
168-
169-
# set values above and below the break to the maximum and minimum for plotting.
170-
x[which(x<min(breaks))] <- min(breaks)
171-
x[which(x>max(breaks))] <- max(breaks)
172-
if(!is.null(which(x < min(breaks))) | !is.null(which(x > max(breaks)))) print("Warning: values out of the range have been set to maximum or minimum of the colorbar")
173-
174-
# plot map
175-
par(mar=c(0.3,0.3,2,0)) # reduce space around plot
176-
image(lon, lat, x, breaks= breaks, col=cols, main=title.main, cex.main=cex.main, xaxt="n", yaxt="n", xlab=NA, ylab=NA)
177-
points(lon.points, lat.points, lwd=2, cex=1.5)
178-
map(add=T)
179-
}
180-
181-
182-
183-

R/plotFun.grid1.R

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#' Plot grid (single plot).
2+
#'
3+
#' Plot a figure based on a regular grid, for a single plot.
4+
#'
5+
#' @param x matrix to be plotted.
6+
#' @param lon array of longitudes
7+
#' @param lat array of latitudes
8+
#' @param lonLims 2-elemtent vector with the range of longitudes to be plotted. By default all the data is plotted.
9+
#' @param latLims 2-elemtent vector with the range of latitudes to be plotted. By default all the data is plotted.
10+
#' @param breaks vector of values defining the intervals to be used in the colorbar.
11+
#' @param palette character vector with the colors for the plot. They will be interpolated to match the number of intervals defined by breaks.
12+
#' @param title.main character string with the title.
13+
#' @param cex.main numeric value giving the title expansion factor. Default: 1.
14+
#' @param lon.points vector of longitudes for grid points to be marked in the map.
15+
#' @param lat.points vector of latitudes for grid points to be marked in the map.
16+
#'
17+
#' @author Ana Casanueva (16.02.2017)
18+
#'
19+
20+
plotFun.grid1 <- function(x, lon, lat, lonLims,latLims, breaks= breaks, palette=palette, cex.main, title.main, lon.points=lon.points, lat.points=lat.points) {
21+
22+
# Plot subregion or not
23+
ind.x <- which(lon >= lonLims[1] & lon <= lonLims[2])
24+
ind.y <- which(lat >= latLims[1] & lat <= latLims[2])
25+
lon <- lon[ind.x]
26+
lat <- lat[ind.y]
27+
x <- x[ind.x, ind.y]
28+
29+
# Number of intervals to plot
30+
lev <- length(breaks)-1;
31+
32+
# Interpolate palette to the number of levels
33+
cols <- colorRampPalette(palette)(lev)
34+
35+
# set values above and below the break to the maximum and minimum for plotting.
36+
if(length(which(x < min(breaks)))!=0 | length(which(x > max(breaks)))!=0) print("Warning: values out of the range have been set to maximum or minimum of the colorbar")
37+
x[which(x<min(breaks))] <- min(breaks)
38+
x[which(x>max(breaks))] <- max(breaks)
39+
40+
# plot map
41+
par(mar=c(0.3,0.3,2,0)) # reduce space around plot
42+
image(lon, lat, x, breaks= breaks, col=cols, main=title.main, cex.main=cex.main, xaxt="n", yaxt="n", xlab=NA, ylab=NA)
43+
points(lon.points, lat.points, lwd=2, cex=1.5)
44+
map(add=T)
45+
}
46+

R/plot.heat.R renamed to R/plotFun.heat.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@
2323
#' @details The two input variables of the desired index need to be provided, tas and either td or hu. Needed packages: HeatStress, RColorBrewer.
2424
#' @import HeatStress RColorBrewer
2525
#' @author Ana Casanueva, 13.12.2018
26-
#' @export plot.heat
26+
#' @export plotFun.heat
2727
#' @examples \dontrun{
2828
#' # Generate data
2929
#' tas <- rnorm(150, mean=15, sd=2)
3030
#' dew <- rnorm(150, mean=8, sd=1)
3131
#' hurs <- sample(1:100,150, replace=T)
3232
#' # Plot the heat plot
33-
#' plot.heat(hu=hurs, ta=tas, heat.index="wbt", title="Heat stress plot", cex.main=1.5,
33+
#' plotFun.heat(hu=hurs, ta=tas, heat.index="wbt", title="Heat stress plot", cex.main=1.5,
3434
#' xlab="Relative Humidity", ylab="Air temp.", n.bins=500)
3535
#' # Add points, change index
36-
#' plot.heat(hu=hurs, ta=tas, heat.index="swbgt", title="Heat stress plot", cex.main=1.5,
36+
#' plotFun.heat(hu=hurs, ta=tas, heat.index="swbgt", title="Heat stress plot", cex.main=1.5,
3737
#' xlab="Relative Humidity", ylab="Air temp.", n.bins=500, add.points=F)
3838
#' # Add contours, change index
39-
#' plot.heat(td=dew, ta=tas, heat.index="wbgt.shade", title="Heat stress plot", cex.main=1.5,
39+
#' plotFun.heat(td=dew, ta=tas, heat.index="wbgt.shade", title="Heat stress plot", cex.main=1.5,
4040
#' xlab="Dew point temp.", ylab="Air temp.", n.bins=500, add.contours=F)
4141
#' }
4242

4343

4444

4545

46-
plot.heat <- function(hu=NULL, td=NULL, ta, xlim=NULL, ylim=range(ta, na.rm=T), heat.index=NULL, breaks.index=NULL, title=NULL, cex.main=1.5, xlab=NULL, ylab=NULL, n.bins=500, add.points=TRUE, add.contours=TRUE, unit.text=NULL, cex.unit=1, cex.textcbar=1.3){
46+
plotFun.heat <- function(hu=NULL, td=NULL, ta, xlim=NULL, ylim=range(ta, na.rm=T), heat.index=NULL, breaks.index=NULL, title=NULL, cex.main=1.5, xlab=NULL, ylab=NULL, n.bins=500, add.points=TRUE, add.contours=TRUE, unit.text=NULL, cex.unit=1, cex.textcbar=1.3){
4747

4848

4949
if(n.bins>100) message("Patience: number of bins is ", n.bins)
@@ -112,7 +112,7 @@ plot.heat <- function(hu=NULL, td=NULL, ta, xlim=NULL, ylim=range(ta, na.rm=T),
112112

113113
# add color bar
114114
par(mar=c(3,0.6,3,4.5))
115-
plot.colorbar(round(breaks.index,4), palette=cols, unit.text, cex.unit, cex.textcbar)
115+
plotFun.colorbar(round(breaks.index,4), palette=cols, unit.text, cex.unit, cex.textcbar)
116116

117117
}
118118

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#' Plot 2-dimensional kernel density plots and the histograms of the two input variables.
1+
#' Plot a 2-dimensional kernel density plot and the histograms of the two input variables.
22
#'
3-
#' Plot 2-dimensional kernel density plots and the histograms of the two input variables.
3+
#' Plot a 2-dimensional kernel density plot and the histograms of the two input variables.
44
#'
55
#' @param var1 vector with data for one variable.
66
#' @param var2 vector with data for another variable.
@@ -16,21 +16,21 @@
1616
#' @return Plot with the 2-dimensional kernel densities and historgrams for the input variables.
1717
#' @details The two-dimensional kernel density estimation is done with the function kde2d in package MASS.
1818
#' @import MASS RColorBrewer
19-
#' @export plot.kde2d.hist
19+
#' @export plotFun.kde2d.hist
2020
#' @author Ana Casanueva, 13.12.2018
2121
#' @examples \dontrun{
2222
#' # Generate data
2323
#' tas <- rnorm(1000, mean=15, sd=2)
2424
#' td <- rnorm(1000, mean=8, sd=1)
25-
#' # Plot "-Dim Kernel density with histograms
26-
#' plot.kde2d.hist(var1=td, var2=tas, xlab="Dew point temp.", ylab="Air temperature",
25+
#' # Plot 2-Dim Kernel density with histograms
26+
#' plotFun.kde2d.hist(var1=td, var2=tas, xlab="Dew point temp.", ylab="Air temperature",
2727
#' n.bins=25, add.contours=FALSE, title="2D density plot", cex.main=2)
2828
#' # add contours for the density values
29-
#' plot.kde2d.hist(var1=td, var2=tas, xlab="Dew point temp.", ylab="Air temperature",
29+
#' plotFun.kde2d.hist(var1=td, var2=tas, xlab="Dew point temp.", ylab="Air temperature",
3030
#' n.bins=25, add.contours=TRUE, title="2D density plot with contours", cex.main=2)
3131
#' }
3232

33-
plot.kde2d.hist <- function(var1, var2, xlim=range(var1, na.rm=T), ylim=range(var2, na.rm=T), breaks.den=NULL, title=NULL, cex.main=1.5, xlab=NULL, ylab=NULL, n.bins=25, add.contours=TRUE){
33+
plotFun.kde2d.hist <- function(var1, var2, xlim=range(var1, na.rm=T), ylim=range(var2, na.rm=T), breaks.den=NULL, title=NULL, cex.main=1.5, xlab=NULL, ylab=NULL, n.bins=25, add.contours=TRUE){
3434

3535

3636
# *** Build data frame with input variables and histograms ***
@@ -90,7 +90,7 @@ plot.kde2d.hist <- function(var1, var2, xlim=range(var1, na.rm=T), ylim=range(va
9090

9191
# add color bar
9292
par(mar=c(3,0.6,3,4.5))
93-
plot.colorbar(round(breaks.den,4), palette=cols, " ", 1, 1.3)
93+
plotFun.colorbar(round(breaks.den,4), palette=cols, " ", 1, 1.3)
9494

9595
# plot title
9696
par(mar=c(0.1,2,0.2,0.5))

0 commit comments

Comments
 (0)