|
| 1 | +#' Barplot with whiskers. |
| 2 | +#' |
| 3 | +#' Barplot with whiskers, for instance to show mean and range of climate projections. |
| 4 | +#' |
| 5 | +#' @param obs observed value. |
| 6 | +#' @param ctl multi-model median/mean value in the historical period. |
| 7 | +#' @param ctl.rg 2-element vector with the multi.model range (e.g. 5-95th percentiles) in the historical period. |
| 8 | +#' @param p1 multi-model median/mean value in the short-term future period. |
| 9 | +#' @param p1.rg 2-element vector with the multi.model range (e.g. 5-95th percentiles) in the short-term future period. |
| 10 | +#' @param p1 multi-model median/mean value in the mid-term future period. |
| 11 | +#' @param p1.rg 2-element vector with the multi.model range (e.g. 5-95th percentiles) in the mid-term future period. |
| 12 | +#' @param p1 multi-model median/mean value in the long-term future period. |
| 13 | +#' @param p1.rg 2-element vector with the multi.model range (e.g. 5-95th percentiles) in the long-term future period. |
| 14 | +#' @param col 4-element vector with the colours for the four bars. |
| 15 | +#' @param ylab character string for the Y-axis. |
| 16 | +#' @param xlab 4-element vector to label the bars. |
| 17 | +#' @param stn.name character with the name of the station. |
| 18 | +#' @param breaks vector of values with the Y-axis ticks. |
| 19 | +#' @param add.lines should horizontal lines be added for reference? Default: FALSE. |
| 20 | +#' @param lines values in the Y-axis to plot a horizontal line. |
| 21 | +#' @param pch.obs type of marker for the observations. Default:8. |
| 22 | +#' @param cex.obs relative size for the marker representing the observations. Default: 1.5. |
| 23 | +#' |
| 24 | +#' @return A bar plot consisting on 4 bars (e.g. historical and 3 future periods) and highlight the observations with a markers. Uncertainty is shown though small segments. |
| 25 | +#' |
| 26 | +#' @author Ana Casanueva (22.03.2019) |
| 27 | +#' |
| 28 | + |
| 29 | +plotFun.barplotScen <- function(obs, ctl, ctl.rg, p1, p1.rg, p2, p2.rg, p3, p3.rg, col, ylab=NULL, xlab=NULL, stn.name=NULL, breaks=seq(0, ceiling(p3.rg[2])), add.lines=F,lines=NULL, pch.obs=8, cex.obs=1.5){ |
| 30 | + |
| 31 | + ylim <- range(breaks) |
| 32 | + centers <- barplot(c(ctl, p1, p2, p3), col=col, ylim=ylim, names.arg=xlab, yaxt="n", ylab=ylab, cex.lab=1.3, border="white", cex.names=1.2) |
| 33 | + if(add.lines){ |
| 34 | + abline(h=lines,lty=5,lwd=0.6) |
| 35 | + } |
| 36 | + barCenters <- centers[1:length(centers)] |
| 37 | + segments(barCenters, c(ctl.rg[1], p1.rg[1], p2.rg[1], p3.rg[1]), barCenters, c(ctl.rg[2], p1.rg[2], p2.rg[2], p3.rg[2])) |
| 38 | + arrows(barCenters, c(ctl.rg[1], p1.rg[1], p2.rg[1], p3.rg[1]), barCenters, c(ctl.rg[2], p1.rg[2], p2.rg[2], p3.rg[2]), angle = 90, code = 3, length = 0.05) |
| 39 | + # add marker for obs |
| 40 | + points(barCenters[1], obs, pch=pch.obs, cex=cex.obs, col="red") |
| 41 | + axis(2, at=breaks, labels=breaks, cex.axis=1.2, las=1) |
| 42 | + usr <- par('usr') |
| 43 | + text(usr[1]+((usr[2]-usr[1])*0.015), usr[4]-((usr[4]-usr[3])*0.05),stn.name, font=2, col='black', adj=0, cex=1.3) |
| 44 | +} |
0 commit comments