Plot a wind rose showing the wind speed and direction for given facets using ggplot2.
Usage
windrose(
speed,
direction,
facet,
n_directions = 12,
n_speeds = 5,
speed_cuts = NA,
col_pal = "GnBu",
ggtheme = c("grey", "gray", "bw", "linedraw", "light", "minimal", "classic"),
legend_title = "Wind Speed",
calm_wind = 0,
variable_wind = 990,
n_col = 1,
...
)
Arguments
- speed
numeric vector of wind speeds.
- direction
numeric vector of wind directions.
- facet
character or factor vector of the facets used to plot the various wind roses.
- n_directions
the number of direction bins to plot (petals on the rose). The number of directions defaults to 12.
- n_speeds
the number of equally spaced wind speed bins to plot. This is used if
speed_cuts
isNA
(default 5).- speed_cuts
numeric vector containing the cut points for the wind speed intervals, or
NA
(default).- col_pal
character string indicating the name of the
RColorBrewer
colour palette to be used for plotting, see 'Theme Selection' below.- ggtheme
character string (partially) matching the
ggtheme
to be used for plotting, see 'Theme Selection' below.- legend_title
character string to be used for the legend title.
- calm_wind
the direction of wind that is considered calm. Following convention of the National Weather Service, winds with a direction of 0 are considered calm by default.
- variable_wind
numeric code for variable winds (if applicable).
- n_col
The number of columns of plots (default 1).
- ...
further arguments passed to
theme
.
Details
This is intended to be used as a stand-alone function for any wind dataset. A
different wind rose is plotted for each level of the faceting variable which
is coerced to a factor if necessary. The facets will generally be the station
where the data were collected, seasons or dates. Currently only one faceting
variable is allowed and is passed to facet_wrap
with
the formula ~facet
.
Note that calm winds are excluded from the wind rose.
Theme Selection
For black and white wind roses that may be preferred if plots are to be used
in journal articles for example, recommended ggtheme
s are 'bw'
,
'linedraw'
, 'minimal'
or 'classic'
and
the col_pal
should be 'Greys'
. Otherwise, any of the sequential
RColorBrewer
colour palettes are recommended for
colour plots.
See also
theme
for more possible arguments to pass to
windrose
.
Examples
# Create some dummy wind data with predominant south to westerly winds, and
# occasional yet higher wind speeds from the NE (not too dissimilar to
# Auckland).
wind_df = data.frame(wind_speeds = c(rweibull(80, 2, 4), rweibull(20, 3, 9)),
wind_dirs = c(rnorm(80, 135, 55), rnorm(20, 315, 35)) %% 360,
station = rep(rep(c("Station A", "Station B"), 2),
rep(c(40, 10), each = 2)))
# Plot a simple wind rose using all the defaults, ignoring any facet variable
with(wind_df, windrose(wind_speeds, wind_dirs))
#> Error in position_stack(reverse = TRUE): could not find function "position_stack"
# Create custom speed bins, add a legend title, and change to a B&W theme
with(wind_df, windrose(wind_speeds, wind_dirs,
speed_cuts = c(3, 6, 9, 12),
legend_title = "Wind Speed\n(m/s)",
legend.title.align = .5,
ggtheme = "bw",
col_pal = "Greys"))
#> Error in position_stack(reverse = TRUE): could not find function "position_stack"
# Note that underscore-separated arguments come from the windrose method, and
# period-separated arguments come from ggplot2::theme().
# Include a facet variable with one level
with(wind_df, windrose(wind_speeds, wind_dirs, "Artificial Auckland Wind"))
#> Error in position_stack(reverse = TRUE): could not find function "position_stack"
# Plot a windrose for each level of the facet variable (each station)
with(wind_df, windrose(wind_speeds, wind_dirs, station, n_col = 2))
#> Error in position_stack(reverse = TRUE): could not find function "position_stack"
if (FALSE) { # \dontrun{
# Save the plot as a png to the current working directory
library(ggplot2)
ggsave("my_windrose.png")
} # }