lc50_plot: LC50 Regression Plots

View source: R/lc50_plot.R

lc50_plotR Documentation

LC50 Regression Plots

Description

Plots every data set: observed points, the fitted curve of the computed method with its pointwise confidence band, and dashed reference lines marking the LC estimate, which is itself marked by a circle where it lies on the fitted curve. By default the concentration axis is on a log10 scale, which gives the classical symmetric S-shaped curve; shape = "linear" restores the original linear axis.

Usage

lc50_plot(
  results,
  save_path = NULL,
  font = "TNM",
  width = 7,
  height = 6,
  dpi = 300,
  unit = NULL,
  shape = c("sigmoid", "linear"),
  ci = TRUE,
  ci_level = 0.95,
  error_bar = TRUE,
  move_thres = 0.5,
  method = NULL,
  lc_ci = TRUE,
  lc_p = TRUE,
  lc_lab_gap = 0.35,
  lc_lab_gap_right = 0.1,
  lc_lab_dy = 0.1,
  lc_lab_lh = 1.05
)

Arguments

results

Result list of lc50_calculate.

save_path

Folder for the png files; NULL (default) displays the plots only.

font

Font family (default "TNM").

width, height

Figure size in inches (default 7 x 6).

dpi

Resolution of the saved files (default 300); at any dpi the figures keep the physical size they have at 300 dpi.

unit

Unit of the concentration (e.g. "mg/L"), used in the LC label and the x-axis title. NULL (the default) is treated as "mg/L"; pass "" to show no unit at all.

shape

"sigmoid" (default): log10 concentration axis, the symmetric S-shaped dose-response curve. "linear": the original linear concentration axis.

ci

Logical (default TRUE): draw the pointwise confidence band of the fitted curve.

ci_level

Confidence level of the curve band and of the replicate error bars (default 0.95).

error_bar

Logical (default TRUE): replicate rows of the same concentration are pooled to a single point, the Abbott-corrected sum(Dead) / sum(Tested) (equal to the replicate mean when the replicate groups are of equal size), with a Wilson score interval at ci_level as the error bar, clipped to [0, 1]. FALSE draws every raw row as a plain point (the previous behaviour).

move_thres

Numeric (default 0.5). A dashed reference line that does not land on a regular tick normally gets an extra tick whose value is labelled next to the axis like a regular tick. If the LC position is at most move_thres regular tick spacings away from the nearest tick (measured on the display axis, i.e. log10 concentrations for shape = "sigmoid"), that label would overlap the neighbouring tick label, so the value is drawn inside the panel instead: the concentration just above the x axis to the right of the vertical dashed line, the mortality just right of the y axis above the horizontal dashed line (each flips to the other side of its dashed line when it would not fit). 0 disables the move; with evenly spaced ticks 0.5 moves every value that is not midway between two ticks.

method

Character scalar, which methods to plot: a subset of c("traditional", "improved", "probit"), or "all" (default) for every method present in the results object.

lc_ci

Logical (default TRUE): show the 95 interval of the LC estimate as a second line of the LC reference label, e.g. (0.98-1.55) below LC50 = 1.23 mg/L. FALSE omits the line.

lc_p

Logical (default TRUE): append the chi-square goodness-of-fit result (chi-square statistic and P value) as an additional line of the LC reference label. FALSE omits the line.

lc_lab_gap

Clearance between the vertical reference line and the near edge of the LC label when the label sits LEFT of the line, in text widths of the label itself (default 0.35). Larger pushes the label further away from the line; smaller moves it towards it.

lc_lab_gap_right

The same clearance when the label sits RIGHT of the line (default 0.1, smaller than lc_lab_gap because the label then hangs below the crossing, where a smaller gap keeps it closer to the reference line).

lc_lab_dy

Clearance between the LC label block and the LC crossing, in y-axis units (default 0.1): the distance from the crossing to the edge of the block that faces it. The block is placed in the diagonal quadrant the fitted curve never enters (above the crossing when the label sits left of the vertical reference line, below it when the label sits right), anchored by that facing edge, so adding lines or changing lc_lab_lh grows the block away from the crossing and never onto the dashed reference line. Larger moves the whole block further from it.

lc_lab_lh

Line spacing of the LC label in multiples of its font size (1 = single spacing, default 1.05). The lines are spaced evenly whichever of them lc_ci / lc_p switches on.

Details

Replicates of the same concentration are pooled and drawn as the Abbott-corrected pooled mortality with Wilson score intervals. The LC reference label is centred around the crossing of the two dashed reference lines. Because the sigmoid only ever passes through the lower-left and upper-right quadrants around that crossing, the label is placed in one of the two free ones: above the crossing when it sits left of the vertical reference line, below it when it sits right, at a clearance of lc_lab_dy. If a replicate error bar reaches into the label block, the block is shifted vertically by the smallest amount that restores a clearance of about one line height from the bar end, preferring the direction that keeps it on its own side of the crossing. The extra x-axis value always sits to the right of the vertical dashed line (it moves to the left only when it would run off the right panel edge); when the label block dips into the value's strip, the block is raised clear of it instead.

Value

Named list of ggplot objects (invisibly).

File names

Saved files are named after the data set plus suffixes for every non-default setting that changes the look (_linear for shape = "linear", _noband for ci = FALSE, _nobar for error_bar = FALSE, _nolcCI for lc_ci = FALSE, _nochi for lc_p = FALSE, and the selected method names), so plots saved to one folder can never overwrite each other.

See Also

lc50_export, lc50_export_plot

Examples

f <- system.file("extdata", "lc50_example.csv", package = "insectecol")
res <- lc50_calculate(lc50_read(f))
plots <- lc50_plot(res, save_path = tempdir())
plots <- lc50_plot(res, shape = "linear", save_path = tempdir())  # original axis
plots <- lc50_plot(res, ci = FALSE, error_bar = FALSE,
                   save_path = tempdir())                          # bare version

insectecol documentation built on Oct. 5, 2026, 5:08 p.m.