section_plot: Make an oceanographic section plot from an x-y-z data frame

View source: R/section_plot.R

section_plotR Documentation

Make an oceanographic section plot from an x-y-z data frame

Description

Creates an oceanographic section plot from a data frame using ggplot2. Returns either an interpolated section or a bubble plot.

Usage

section_plot(
  df,
  x,
  y,
  z,
  bottom = NULL,
  interpolate = FALSE,
  interp_method = "mba",
  log_y = FALSE,
  xlab = "Distance",
  ylab = "Depth",
  zlab = "Variable",
  ybreaks = waiver(),
  xbreaks = waiver(),
  zbreaks = waiver(),
  contour = NULL,
  contour_label_cex = 0.8,
  contour_color = "white",
  xlim = NULL,
  ylim = NULL,
  zlim = NULL,
  zscale = "viridis",
  zcolor = "black",
  add_bottom = NULL,
  sampling_indicator = "lines",
  legend.position = "right",
  base_size = 10,
  ...
)

Arguments

df

Data frame containing the data

x

Character specifying the column name which should be used as x (=distance) axis

y

Character specifying the column name which should be used as y (=depth) axis. The y axis will be inverted in the resulting plot.

z

Character specifying the column name which should be for bubbles or interpolation fill depending on the interpolate argument.

bottom

Optional character specifying the column name which contains bottom depths OR a data frame with x-axis values in the first column and bottom depths in the second column. If provided, unique combinations of x and bottom will be used to plot bottom for the section plot

interpolate

Logical indicating whether an interpolated section plot (TRUE) or a bubble plot (FALSE) should be returned.

interp_method

(interpolate = TRUE only). Character specifying the interpolation method. See interpolate_section.

log_y

logical indicating whether the y-axis should be log10(y + 10) transformed before plotting. Helps showing differences close to the surface if some stations are much deeper than others.

xlab, ylab, zlab

Character specifying the labels for the x-axis, y-axis and legend, respectively.

xbreaks, ybreaks, zbreaks

Numeric vector specifying the breaks for the x-axis, y-axis and legend. See scale_continuous.

contour

(interpolate = TRUE only). Numeric vector defining breaks for contour lines. Use NULL not to plot the contour lines.

contour_label_cex

Numeric giving the cex (=size) parameter for contour labels. See geom_dl.

contour_color

Character defining the color to be used for contour lines and labels.

xlim, ylim

Numeric vector of length two providing limits of the scale. Use NA to refer to the existing minimum or maximum. Use NULL for default limits.

zlim

Numeric vector of length two providing limits for fill or bubble size. Any values outside these limits will get the extreme values defined by zrange (using the squish function).

zscale

(interpolate = TRUE only). Character specifying the color scale for interpolation tile fill. Either one of the scale_colour_viridis_c option alternatives ("A", "B", "C", or "D") or "gradient2" for a scale_colour_gradient2 (red-white-blue) color scale. Note that you can use the ggplot2 color scale arguments to adjust the color scales as you want. Just place them inside the section_plot function.

zcolor

(interpolate = FALSE only). Character specifying the color of bubbles. Use column name in df to scale a variable to bubble color (not implemented yet, here as a reminder).

add_bottom

Numeric vector of length two providing the depths that should be added to bottom at the extremes (range) of xbreaks. Useful for extending the plot giving space for graphical elements.

sampling_indicator

(interpolate = TRUE only). Character giving the style of sampling indicator. Alternatives:

  • "lines" A dashed line reaching from data start depth to end depth at each station. Recommended for CTD sections.

  • "points" Points indicating the vertical and horizontal location of sample. Recommended for water samples.

  • "ticks" A black tick mark above the plot indicating the horizontal location of each station. A way to avoid clutter.

  • "none" No sampling indicator will be plotted.

legend.position

Position for the ggplot legend. See the argument with the same name in theme.

base_size

Base size parameter for ggplot. See theme_bw.

...

Additional arguments passed to color and size scales. See scale_colour_gradient2, scale_colour_viridis_c and scale_size.

Details

Note that you can use the ggplot2 color and size scale arguments to adjust the scales as you want. Just place them inside the section_plot function. See scale_colour_gradient2, scale_colour_viridis_c and scale_size.

Value

Returns either an interpolated section (geom_tile) or a bubble (geom_point) ggplot2 object.

Author(s)

Mikko Vihtakari

Examples

# Bubble plots
section_plot(df = chlorophyll[grepl("KpN.|Kb[0-4]", chlorophyll$Station),], x = "lon", y = "From",
  z = "Chla")

# Interpolated CTD sections
## Standard temperature section plot. Difficult to see surface due to large differences in y-scale
section_plot(ctd_rijpfjord, x = "dist", y = "pressure", z = "temp", bottom = "bdepth",
interpolate = TRUE)

## Logarithmic y axis
section_plot(ctd_rijpfjord, x = "dist", y = "pressure", z = "temp", bottom = "bdepth",
interpolate = TRUE, log_y = TRUE)

## Contour lines
section_plot(ctd_rijpfjord, x = "dist", y = "pressure", z = "temp", bottom = "bdepth",
interpolate = TRUE, log_y = TRUE, contour = c(-1.8, 0, 1, 3))

MikkoVihtakari/PlotSvalbard documentation built on July 12, 2022, 10:20 a.m.