plot_weather: Plot weather curves for a given winter

Description Usage Arguments Value Examples

View source: R/plot_weather.R

Description

This function plots weather variables and indices calculated with the function analyze_weather. It returns a ggplot plot, which means you can use it together with other ggplot2 functions (see examples).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
plot_weather(
  weather_analyzed,
  term = c("snow_depth", "precip", "temp_min", "temp_max", "temp_avg",
    "cumulative_precitation", "prec_snow_ratio", "prec_snow_diff", "snow_prec_ratio",
    "snow_prec_diff")[c(1, 2)],
  factor_mult = rep(1, length(term)),
  add_events = c("", "events3", "events4", "eventsX")[1],
  first_half = TRUE,
  cols = c(),
  units = c(),
  title = ""
)

Arguments

weather_analyzed

data.frame. output 'data.frame' from the analyze_weather function. This data.frame may contain time series of snow_depth, precipitation, accumulated precipitation, temperature (min, max, avg), and ratio and difference of snow_depth and cumulative precipitation (and vice-versa).

term

character. term to be plotted.

factor_mult

numeric, vector. numeric factor to be multipled by each variable (defined in the argument 'term'), so that all variables are plotted in the same scale

cols

character or number. vector. sequence of colors for plotting each term, in the same order as term.

units

character. vector. vector of units of each of the terms.

Value

a ggplot with the terms plotted.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
library(ggplot2)
library(dplyr)
data(weather_mittadalen)

weather_2019 <- weather_mittadalen %>%
  dplyr::filter(year == 2019)

weather_condition_2019 <-
  with(weather_2019, analyze_weather(date, snow_depth, prec, temp_min, temp_max,
                                     temp_avg, start = "first_permanent_snow",
                                     plot_first_snow = T))

plot_weather(weather_condition_2019, term = c("snow_depth", "precip"))
plot_weather(weather_condition_2019, term = c("snow_de", "cum"))
plot_weather(weather_condition_2019, term = c("snow_de", "cum"), add_events = "events3")
plot_weather(weather_condition_2019, term = c("snow_de", "cum", "snow_prec_ratio"))
plot_weather(weather_condition_2019, term = c("snow_de", "cum", "snow_prec_ratio"),
             factor_mult = c(1,1,100))
plot_weather(weather_condition_2019, term = c("snow_de", "cum", "snow_prec_ratio"),
             factor_mult = c(.01,.01,1), add_events = "events3")

# configure details in your plot using further ggplot2 functions
plot_weather(weather_condition_2019, term = c("snow_de", "cum"), add_events = "events3") +
  theme_bw() +
  theme(legend.position = "bottom") +
  labs(y = "Weather variable value")

bniebuhr/winteranalyzer documentation built on Dec. 31, 2020, 8:56 p.m.