Skip to contents

This function plots back trajectories. This function requires that data are imported using the openair::importTraj() function.

Usage

traj_plot(
  data,
  lon = "lon",
  lat = "lat",
  colour = NULL,
  facet = NULL,
  alpha = 1,
  n_points = 12,
  map = TRUE,
  map_fill = "grey95",
  map_colour = "grey85",
  map_alpha = 0.5,
  lon_range = NULL,
  lat_range = NULL,
  crs = 4326,
  ...
)

Arguments

data

Data frame, the result of importing a trajectory file using openair::importTraj().

lon

Column containing the longitude, as a decimal.

lat

Column containing the latitude, as a decimal.

colour

A column to colour the paths by (for example, "date" or a pollutant like "pm2.5").

facet

How to facet the plot.

alpha

Transparency of the plots/lines, where 1 is completely opaque and 0 is completely transparent.

n_points

A dot is placed every n_points along each full trajectory. For hourly back trajectories points are plotted every npoint hours. This helps to understand where the air masses were at particular times and get a feel for the speed of the air (points closer together correspond to slower moving air masses). If n_points = NULL then no points are added.

map

Should a base map be drawn? If TRUE the world base map from the maps package is used.

map_fill

Fill colour of map.

map_colour

Line colour of map.

map_alpha

Alpha of map.

lon_range, lat_range

Longitude and latitude range, provided as a numeric vector of length 2.

crs

The coordinate reference system (CRS) used for the base map. Defaults to 4326, which behaves similarly to Cartesian coordinates. A useful alternative could be 3035 (the "lambert" projection).

...

Arguments passed on to ggplot2::coord_sf

expand

If TRUE, the default, adds a small expansion factor to the limits to ensure that data and axes don't overlap. If FALSE, limits are taken exactly from the data or xlim/ylim.

default_crs

The default CRS to be used for non-sf layers (which don't carry any CRS information) and scale limits. The default value of NULL means that the setting for crs is used. This implies that all non-sf layers and scale limits are assumed to be specified in projected coordinates. A useful alternative setting is default_crs = sf::st_crs(4326), which means x and y positions are interpreted as longitude and latitude, respectively, in the World Geodetic System 1984 (WGS84).

datum

CRS that provides datum to use when generating graticules.

label_graticule

Character vector indicating which graticule lines should be labeled where. Meridians run north-south, and the letters "N" and "S" indicate that they should be labeled on their north or south end points, respectively. Parallels run east-west, and the letters "E" and "W" indicate that they should be labeled on their east or west end points, respectively. Thus, label_graticule = "SW" would label meridians at their south end and parallels at their west end, whereas label_graticule = "EW" would label parallels at both ends and meridians not at all. Because meridians and parallels can in general intersect with any side of the plot panel, for any choice of label_graticule labels are not guaranteed to reside on only one particular side of the plot panel. Also, label_graticule can cause labeling artifacts, in particular if a graticule line coincides with the edge of the plot panel. In such circumstances, label_axes will generally yield better results and should be used instead.

This parameter can be used alone or in combination with label_axes.

label_axes

Character vector or named list of character values specifying which graticule lines (meridians or parallels) should be labeled on which side of the plot. Meridians are indicated by "E" (for East) and parallels by "N" (for North). Default is "--EN", which specifies (clockwise from the top) no labels on the top, none on the right, meridians on the bottom, and parallels on the left. Alternatively, this setting could have been specified with list(bottom = "E", left = "N").

This parameter can be used alone or in combination with label_graticule.

lims_method

Method specifying how scale limits are converted into limits on the plot region. Has no effect when default_crs = NULL. For a very non-linear CRS (e.g., a perspective centered around the North pole), the available methods yield widely differing results, and you may want to try various options. Methods currently implemented include "cross" (the default), "box", "orthogonal", and "geometry_bbox". For method "cross", limits along one direction (e.g., longitude) are applied at the midpoint of the other direction (e.g., latitude). This method avoids excessively large limits for rotated coordinate systems but means that sometimes limits need to be expanded a little further if extreme data points are to be included in the final plot region. By contrast, for method "box", a box is generated out of the limits along both directions, and then limits in projected coordinates are chosen such that the entire box is visible. This method can yield plot regions that are too large. Finally, method "orthogonal" applies limits separately along each axis, and method "geometry_bbox" ignores all limit information except the bounding boxes of any objects in the geometry aesthetic.

ndiscr

Number of segments to use for discretising graticule lines; try increasing this number when graticules look incorrect.

default

Is this the default coordinate system? If FALSE (the default), then replacing this coordinate system with another one creates a message alerting the user that the coordinate system is being replaced. If TRUE, that warning is suppressed.

clip

Should drawing be clipped to the extent of the plot panel? A setting of "on" (the default) means yes, and a setting of "off" means no. In most cases, the default of "on" should not be changed, as setting clip = "off" can cause unexpected results. It allows drawing of data points anywhere on the plot, including in the plot margins. If limits are set via xlim and ylim and some data points fall outside those limits, then those data points may show up in places such as the axes, the legend, the plot title, or the plot margins.

See also

the {openairmaps} package for interactive trajectory maps using {leaflet}

Other trajectory analysis functions: traj_cluster(), traj_level()