#' Weather plot
#'
#' This function allows you to plot weather data across a single cropping season (Aug - July).
#' @param x rainfall data
#' @param y temperature or spore release data
#' @param yaxis1 limits for side 2 y axis
#' @param yaxis2 limits for side 4 y axis
#' @param ... arguments to be passed to/from other methods (see barplot)
#' @keywords weather rainfall
#' @export
#' @examples
#' weather_plot(mydata$Rainfall, mydata$Temperature, yaxis1 = c(0,40), yaxis2 = c(-20,40))
weather_plot <- function(x, y, yaxis1, yaxis2, ...) {
par(mar = c(7,7,3,5))
plot(x, type = "h",
xlab = "",
ylab = "",
cex.lab = 1.5,
lwd = 1,
bty = "n",
axes = FALSE,
col = "blue",
ylim = yaxis1,
...)
par(las = 1)
axis(side = 1,
at = c(0, 17, 48, 78.5, 109, 139.5, 169.5, 199.5, 228.5, 259, 289.5, 320, 350.5, 367),
labels = c("","Aug", "Sep", "Oct", "Nov", "Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", ""),
tick =FALSE,
cex.axis = 1)
axis(side = 1, at = c(0, 32, 63, 94, 124, 155, 186, 214, 245, 275, 306, 336, 366),
labels = FALSE,
tick = TRUE,
lwd = 1, ...)
axis(side = 2,
line = -1,
lwd = 1,
cex.axis = 1, ...)
# Add Av Temp
par(new = TRUE)
plot(y, type = "l", col = "red", axes = FALSE, ylab = "", xlab = "", ylim = yaxis2, cex.axis = 1.5, lwd = 1)
axis(side = 4, cex.axis = 1, lwd = 1, line = -1)
# Axis labels
par(las = 0)
mtext("Average temperature" ~ (~degree~C), side = 4, line = 3, cex.lab = 1)
mtext("Rainfall (mm)", side = 2, line = 3, cex.lab = 1)
par(las = 1)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.