Learn R Programming

clifro (version 3.2-5)

plot,cfWind,missing-method: Plot Clifro Wind Objects

Description

Various plot methods for exploring wind speed and direction patterns for given CliFlo stations.

Usage

# S4 method for cfWind,missing
plot(
  x,
  y,
  n_directions = 12,
  n_speeds = 5,
  speed_cuts = NULL,
  col_pal = "GnBu",
  ggtheme = c("grey", "gray", "bw", "linedraw", "light", "minimal", "classic"),
  n_col = 1,
  ...
)

# S4 method for cfWind,missing direction_plot( x, y, ggtheme = c("grey", "gray", "bw", "linedraw", "light", "minimal", "classic"), contours = 10, n_col = 1, ... )

# S4 method for cfDataList,missing direction_plot(x, y, ...)

# S4 method for cfDataList,numeric direction_plot(x, y, ...)

# S4 method for cfWind,missing speed_plot( x, y, ggtheme = c("grey", "gray", "bw", "linedraw", "light", "minimal", "classic"), scales = c("fixed", "free_x", "free_y", "free"), n_col = 1, ... )

# S4 method for cfDataList,missing speed_plot(x, y, ...)

# S4 method for cfDataList,numeric speed_plot(x, y, ...)

Arguments

x

a cfWind or cfDataList object.

y

missing if x is a .cfWind object, otherwise a number indicating the dataframe to plot in the cfDataList (defaults to 1).

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 spd_cuts is NA (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.

n_col

the number of columns of plots (default 1).

...

further arguments passed to theme.

contours

the number of contour lines to draw (default 10).

scales

character string partially matching the scales argument in the link[ggplot2]{facet_wrap} function.

Theme Selection

For black and white windroses that may be preferred if plots are to be used in journal articles for example, recommended ggthemes 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.

Details

If x is a cfDataList, by default the first datatype will be plotted unless y is supplied.

Examples

Run this code
# NOT RUN {
# Retrieve maximum wind gust data at the Reefton Ews station from CliFlo
# (public data)
reefton_wind = cf_query(cf_user(), cf_datatype(2, 2, 1, 1), cf_station(),
                        start_date = "2012-01-01-00")

class(reefton_wind)

# Examples of the default plots --------------------------------------------

# Plot a windrose
plot(reefton_wind)

# Plot the wind direction contours
direction_plot(reefton_wind)

# Plot the wind speed time-series
speed_plot(reefton_wind)

# Examples of changing the defaults ----------------------------------------

# Plot black and white windroses
plot(reefton_wind, ggtheme = "bw", col_pal = "Greys")
plot(reefton_wind, ggtheme = "linedraw", col_pal = "Greys")
plot(reefton_wind, ggtheme = "classic", col_pal = "Greys")
plot(reefton_wind, ggtheme = "minimal", col_pal = "Greys")

# Plot the wind directions using 20 contours and the ggtheme 'classic'
direction_plot(reefton_wind, ggtheme = "classic", contours = 20)

# Enlarge all the text to 18pt
library(ggplot2) # for element_text() and geom_point()
direction_plot(reefton_wind, ggtheme = "classic", contours = 20,
               text = element_text(size = 18))

# Include the actual observations in the plots
direction_plot(reefton_wind) + geom_point(alpha = .2, size = 3)

speed_plot(reefton_wind, ggtheme = "classic", text = element_text(size = 16)) +
  geom_point(shape = 1, size = 3)
# or equivalently using base graphics:
plot(reefton_wind$Date, reefton_wind$Speed, type = 'o',
     xlab = NA, ylab = "Daily max gust (m/s)", las = 1, main = "Reefton Ews")

# Example of plotting a cfDataList -----------------------------------------
# Collect both surface wind run and hourly surface wind observations from
# Reefton Ews
reefton_list = cf_query(cf_user(), cf_datatype(2, 1, 1:2, 1),
                        cf_station(), "2012-01-01 00", "2012-02-01 00")

reefton_list

class(reefton_list) #cfDataList

# Plot the first (default) dataframe
plot(reefton_list) # Error - no wind directions for wind run datatypes
# Try speed_plot instead
speed_plot(reefton_list)

# Plot the second dataframe in the cfDataList
plot(reefton_list, 2)           # identical to plot(reefton_list[2])
speed_plot(reefton_list, 2)     # identical to speed_plot(reefton_list[2])
direction_plot(reefton_list, 2) # identical to direction_plot(reefton_list[2])

# Save the ggplot externally -----------------------------------------------

# Save the plot as a png to the current working directory
library(ggplot2) # for ggsave()
ggsave("my_wind_plot.png")
# }

Run the code above in your browser using DataLab