plot_field_discrete: Plot a gridded field using discrete scale

Description Usage Arguments Details Value

View source: R/plot_field_discrete.R

Description

This function tries to produce high-quality maps of gridded fields using a discrete color-scale. The function is based on ggplot2. World borders will be used with the plot.

Usage

1
2
3
4
5
6
7
plot_field_discrete(x, lon, lat, lonlim = "auto", latlim = "auto",
  breaks = c(), labels = c(), color_scale = "Spectral",
  rev_color_scale = F, show_lat_lon_labels = T, varname = "x",
  mask = NULL, siglev = NULL, plot_only_sig = F, smooth = F,
  smooth_factor = 5, smooth_theta = 0.5, line_width = 0.5,
  dot_size = 0.5, grid_step = 10, font_size = 18,
  show_legend = TRUE)

Arguments

x

The field to be plotted, it can be both a matrix or a vector. See Details for more information.

lon

Vector of longitude values. Longitude should be in the range c(-180, 180), otherwise it will be transformed

lat

Vector of latitude values

lonlim

A vector of two values defining the longitude limits for the plot. The default is 'auto': it tries to detect the extreme directly from the provided longitude values.

latlim

A vector of two values defining the latitude limits for the plot. The default is 'auto': it tries to detect the extreme directly from the provided latitude values.

breaks

The vector to be used to define the color scale. If the vector contains N values (n_1, n_2, ..., n_k), the scale will have N+1 intervals: "<n_1", "n_1, n_2", ..., ">n_k". If breaks are not defined they are automatically computed diving the range of the plotted field in 5 intervals.

labels

A character vector containing all the labels associated to the breaks, the labels' lenght should have N+1 length with N the breaks' length

color_scale

This parameter defines the color palette. It might be a string defining the name of a colorbrewer (see colorbrewer2.org) palette or a list of all the colors associated to each interval.

rev_color_scale

logical value to define if the color_scale should be used reversed

show_lat_lon_labels

logical value that defines if labels for longitude and latitude should be shown

varname

Name of the plotted variable that appears on the legend bar

mask

Field of the same size of x that will be used to mask the values according to the parameter siglev (usually used to indicate statistical significance)

siglev

Scalar value that is used with mask to "mask" the values. All the points where mask <= siglev will be considered "significant" and then marked with dots (if plot_only_sig is FALSE)

plot_only_sig

If TRUE only the significant points will be plotted, otherwise the significance will be indicated with dots

smooth

Logical value that defines if a smoothing will be applied to the field

smooth_factor

The amplitude of the smoothing, the value indicates the "multiplication factor", i.e. how many points are used for each original grid points

line_width

Line width used for the plot

dot_size

Size of the dots used to indicate the significance

grid_step

Interval used for the lat-lon grid

font_size

Size of the fonts used in the plot

show_legend

Logical value to define if the colorbar should be visible

theta

This is the theta parameter of the function image.smooth from the fields package used for smoothing

Details

Details The field x should be or a matrix/array with 2 dimensions (consistent with lat and lon) or a vector. In the latter, it should have the same length of lat and lon to have a list of grid points. The returned ggplot object can be then combined with other ggplot layers, including coord* layers. We do not suggest to use projections because they are not well implemented with raster/tiles like in this case, especially when the latitude range is very close to the poles. To have a good representation of the field we suggest to add the layer coord_equal() or coord_quickmap() Comments about smoothing, description of the procedure.

Value

A ggplot object


matteodefelice/panas documentation built on March 4, 2020, 4:19 a.m.