plot_climate_data | R Documentation |
Readily displays annotated climate time series on a common plot with many configurable options.
plot_climate_data(
x,
series,
start = NULL,
end = NULL,
ma = NULL,
baseline = NULL,
yearly = FALSE,
make_yearly_data... = list(),
ma_sides = 1L,
interpolate = FALSE,
plot_type = c("single", "multiple"),
as_zoo = TRUE,
type = "l",
bg = scales::alpha("gray", 0.1),
xlab = "Year",
ylab = NULL,
unit = NULL,
main = NULL,
col = NULL,
col_fun = colorspace::rainbow_hcl,
col_fun... = list(l = 65),
alpha = 0.9,
lwd = 2,
legend... = list(),
add = FALSE,
conf_int = FALSE,
ci_alpha = 0.3,
polygon... = list(),
trend = FALSE,
trend_lwd = lwd,
trend_legend_inset = c(0.2, 0.2),
print_trend_ci = TRUE,
trend_format = ifelse(print_trend_ci, "1.3f", "1.2f"),
trend... = list(),
extra_trends = list(),
loess = FALSE,
loess... = list(),
loess_series = NULL,
lines.loess... = list(),
xaxt = "n",
get_x_axis_ticks... = list(),
segmented = FALSE,
segmented... = list(),
plot.segmented... = list(),
mark_segments = c("none", "lines", "points"),
vline... = list(),
points.segmented... = list(),
make_standardized_plot_filename... = list(),
start_callback = NULL,
end_callback = NULL,
sign = TRUE,
sign_callback = rlang::expr(text(graphics::par("usr")[2], graphics::par("usr")[3],
labels = "@priscian", adj = c(1, -0.5))),
save_png = FALSE,
save_png_dir,
png... = list(),
...
)
x |
A data set (down)loaded by function |
series |
A vector containing the column names of the climate series to be plotted. If |
start, end |
Integer values of the starting and ending years of the plot, respectively; if either is given as |
ma |
The size of the |
baseline |
An integer year or, more typically, range of years on which the climate-series anomalies will be centered. If |
plot_type |
Passed to |
type |
What type of plot should be drawn; see |
col |
A vector of colors, each for plotting a member of |
col_fun |
If |
col_fun... |
Takes a list of arguments to be passed to function |
alpha |
Sets the color transparency of the climate series to a new level in [0, 1]. If |
lwd |
A vector of line widths, each for plotting a member of |
conf_int |
Logical; if |
ci_alpha |
Sets the color transparency of the temperature-series CIs to a new level in [0, 1]. If |
... |
Passed to |
omit_series |
A vector containing the column names of the climate series NOT to be plotted if |
## Not run:
inst <- get_climate_data(download=FALSE, baseline=TRUE)
series <- c("GISTEMP Global", "NCEI Global", "HadCRUT4 Global", "Cowtan & Way Krig. Global", "BEST Global (Water Ice Temp.)", "JMA Global", "RSS TLT 3.3 -70.0/82.5", "UAH TLT 6.0 Global", "RATPAC-A 850-300 mb Global")
plot_climate_data(inst, series=series, 1880, ma=12, lwd=2)
########################################
## Plot instrumental series with 95% confidence intervals.
########################################
series <- c("Cowtan & Way Krig. Global", "HadCRUT4 Global")
plot_climate_data(inst, series=series, 1880, ma=12, lwd=2, conf_int=TRUE)
########################################
## Plot instrumental series and trend line.
########################################
series <- c("GISTEMP Global", "NCEI Global", "HadCRUT4 Global", "RSS TLT 3.3 -70.0/82.5", "UAH TLT 6.0 Global")
plot_climate_data(inst, series=series, 1979, ma=12, lwd=2, show_trend=TRUE)
########################################
## Plot piecewise linear trends based on changepoint analysis (similar to Cahill et al. 2015, dx.doi.org/10.1088/1748-9326/10/8/084002).
########################################
## Prepare trend data.
baseline <- TRUE
d <- get_climate_data(download=FALSE, baseline=baseline)
m <- list()
m$series <- c("GISTEMP Global", "NCEI Global", "HadCRUT4 Global")
m$range <- list(start=1880, end=NULL)
m$col <- suppressWarnings(brewer.pal(length(m$series),"Paired"))
length(m$col) <- length(m$series); names(m$col) <- m$series
m$data <- d[d$year >= ifelse(!is.null(m$range$start), m$range$start, -Inf) & d$year <= ifelse(!is.null(m$range$end), m$range$end, Inf), ]
for (s in m$series) {
m[[s]]$lm <- lm(eval(substitute(b ~ yr_part, list(b=as.symbol(s)))), data=m$data)
summary(m[[s]]$lm)
m[[s]]$warming <- coef(m[[s]]$lm)[2L] * diff(range(m[[s]]$lm$model[, 2L]))
m[[s]]$rate <- coef(m[[s]]$lm)[2L] * 10
m[[s]]$rateText <- eval(substitute(expression(paste(Delta, "T = ", r, phantom(l) * degree, "C/dec.", sep="")), list(r=sprintf(m[[s]]$rate, fmt="%+1.3f"))))
m[[s]]$col <- m$col[s]
}
## Plot series.
plot_climate_data(d, m$series, m$range$start, m$range$end, ma=12, lwd=2, col=m$col, baseline=baseline)
## Create changepoint model and plot results.
library(segmented)
changepoints <- 3L
for (s in m$series) {
sm <- segmented::segmented(m[[s]]$lm, ~ yr_part, NA, seg.control(stop.if.error=TRUE, K=changepoints))
print(sm)
plot(sm, add=TRUE, lwd=2, col=m[[s]]$col, rug=FALSE)
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.