|
1 | 1 | #' Plot heat index as a function of the input variables. |
2 | 2 | #' |
3 | | -#' The index is calculated with the R package \code{HeatStress} or provided by the user. |
| 3 | +#' Plot heat index as a function of the input variables. The index is calculated with the R package \code{HeatStress} or provided as a vector by the user. |
4 | 4 | #' |
5 | 5 | #' @param hu vector with data for the variable to be plotted in the X-axis or relative humidity data. \code{hu} or \code{td} are mandatory. |
6 | | -#' @param td vector with data for the variable to be plotted in the X-axis or dew point temperature data.\code{hu} or \code{td} are mandatory. |
| 6 | +#' @param td vector with data for the variable to be plotted in the X-axis or dew point temperature data. \code{hu} or \code{td} are mandatory. |
7 | 7 | #' @param ta vector with with data for the variable to be plotted in the Y-axis or temperature data. |
8 | 8 | #' @param heat.index vector with data to plot with colour markers or character with the heat index to plot as a function of the two input variables. Available (based on 2 variables): swbgt, hi, wbt.Stull, wbgt.Bernard, apparentTemp, effectiveTemp, humidex, discomInd. |
9 | 9 | #' @param xlim 2-element vector with X-axis limits for the density plot. Default: range of hu/td. |
10 | 10 | #' @param ylim 2-element vector with Y-axis limits for the density plot. Default: range of ta. |
11 | 11 | #' @param breaks.index vector of breaks for the heat index values. By default, breaks is adjusted to the minimum and maximum values of the index. |
12 | 12 | #' @param n.bins number of bins for kernel density calculation, only when 'heat.index' is a character. Default= 500 |
13 | 13 | #' @param add.contours logical. Add (default) or not contours for heat index values. It is only valid when 'heat.index' is a character. |
14 | | -#' @param add.points logical. Add (default) or not points with the actual time series. It is only valid when 'heat.index' is a character |
| 14 | +#' @param add.points logical. Add (default) or not points with the actual time series. It is only valid when 'heat.index' is a character. |
15 | 15 | #' @param xlab X-axis label. |
16 | 16 | #' @param ylab Y-axis label. |
17 | 17 | #' @param title title above the plot. |
|
20 | 20 | #' @param cex.unit numeric value giving the expansion factor of the units text. Default:1. |
21 | 21 | #' @param cex.textcbar numeric value giving the expansion factor of the colorbar text. Default:1.3. |
22 | 22 | #' @return Scatter (if 'heat.index' is a vector) or image (if 'heat.index' is a character) plot with the heat index values as a function of the input variables. |
23 | | -#' @details When 'heat.index' is a character, the index is calculated and the two input variables of the desired index need to be provided, tas and either td or hu. Needed packages: HeatStress, RColorBrewer. |
24 | | -#' When 'heat.index' is a vector, the variable to be plotted in the X-axis should be included in 'hu' or 'td' and the plotted in the Y-axis in 'ta'. |
| 23 | +#' @details When 'heat.index' is a \strong{character}, the index is calculated and the two input variables of the desired index need to be provided, tas and either td or hu. Needed packages: HeatStress, RColorBrewer. |
| 24 | +#' When 'heat.index' is a \strong{vector}, the variable to be plotted in the X-axis should be included in 'hu' or 'td' and the plotted in the Y-axis in 'ta'. |
25 | 25 | #' @import HeatStress RColorBrewer |
26 | | -#' @author Ana Casanueva, 13.12.2018 |
| 26 | +#' @author Ana Casanueva, 14.08.2019 |
27 | 27 | #' @export plotFun.heat |
28 | 28 | #' @examples \dontrun{ |
29 | 29 | #' # Generate data |
|
39 | 39 | #' # Add contours, change index |
40 | 40 | #' plotFun.heat(td=dew, ta=tas, heat.index="wbgt.shade", title="Heat stress plot", cex.main=1.5, |
41 | 41 | #' xlab="Dew point temp.", ylab="Air temp.", n.bins=500, add.contours=F) |
| 42 | +#' # Plot only scatter plot with coloured markers |
| 43 | +#' hi <- runif(150, -2,5) + 90 |
| 44 | +#' plotFun.heat(td=dew, ta=tas, heat.index = hi, ylab="Ta", xlab="Td", unit.text = "degC") |
42 | 45 | #' } |
43 | 46 |
|
44 | 47 |
|
45 | 48 |
|
46 | 49 |
|
| 50 | + |
47 | 51 | 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){ |
48 | 52 |
|
49 | 53 |
|
@@ -114,7 +118,7 @@ plotFun.heat <- function(hu=NULL, td=NULL, ta, xlim=NULL, ylim=range(ta, na.rm=T |
114 | 118 | } else{ |
115 | 119 | class <- classInt::classIntervals(heat.index, lev, style = "fixed", fixedBreaks=breaks.index) |
116 | 120 | colcode <- classInt::findColours(class,cols) |
117 | | - plot(df$x, df$y, bg=colcode, pch=21, xaxs="i", yaxs="i", xlim= xlim, ylim=ylim,las=1, cex=2, lwd=1, xlab=NA, ylab=NA) |
| 121 | + plot(df$x, df$y, bg=colcode, pch=21, xaxs="i", yaxs="i", xlim= xlim, ylim=ylim,las=1, cex=2, lwd=1, xlab=NA, ylab=NA, cex.axis=1.5, main=title, cex.main=cex.main) |
118 | 122 | } |
119 | 123 |
|
120 | 124 | # add labels for the axis |
|
0 commit comments