ggplot_gaussian_2D: Plot a 2D Gaussian via ggplot

Description Usage Arguments Value Author(s) Examples

View source: R/ggplot_gaussian_2D.R

Description

Plot a 2D Gaussian via ggplot

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
ggplot_gaussian_2D(
  gauss_data,
  normalize = TRUE,
  contour_thickness = 0.04,
  contour_color = "black",
  bins = 15,
  viridis_dir = 1,
  viridis_opt = "B",
  x_lab = "X values",
  y_lab = "Y values",
  axis.text = element_text(size = 6),
  axis.title = element_text(size = 7),
  axis.ticks = element_line(size = 0.3),
  plot.margin = unit(c(0.1, 0.1, 0.1, 0.1), "cm"),
  ...
)

Arguments

gauss_data

Data.frame with X_values, Y_values, and predicted_values, e.g. exported from predict_gaussian_2D()

normalize

Default TRUE, should predicted_values be normalized on a 0 to 1 scale?

contour_thickness

Thickness of contour lines

contour_color

Color of the contour lines

bins

Number of bins for the contour plot

viridis_dir

See "direction" in scale_fill_viridis_c()

viridis_opt

See "option" in scale_fill_viridis_c()

x_lab

Arguments passed to xlab()

y_lab

Arguments passed to ylab()

axis.text

Arguments passed to axis.text

axis.title

Arguments passed to axis.title

axis.ticks

Arguments passed to axis.ticks

plot.margin

Arguments passed to plot.margin

...

Other arguments supplied to ggplot2::theme()

Value

A ggplot object that uses metR::geom_contour_fill() to display the 2D Gaussian

Author(s)

Vikram B. Baliga

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
if (interactive()) {
  ## Load the sample data set
  data(gaussplot_sample_data)

  ## The raw data we'd like to use are in columns 1:3
  samp_dat <-
    gaussplot_sample_data[,1:3]


  #### Example 1: Unconstrained elliptical ####
  ## This fits an unconstrained elliptical by default
  gauss_fit <-
    fit_gaussian_2D(samp_dat)

  ## Generate a grid of x- and y- values on which to predict
  grid <-
    expand.grid(X_values = seq(from = -5, to = 0, by = 0.1),
                Y_values = seq(from = -1, to = 4, by = 0.1))

  ## Predict the values using predict_gaussian_2D
  gauss_data <-
    predict_gaussian_2D(
      fit_object = gauss_fit,
      X_values = grid$X_values,
      Y_values = grid$Y_values,
    )

  ## Plot via ggplot2 and metR
  library(ggplot2); library(metR)
  ggplot_gaussian_2D(gauss_data)

  ## Produce a 3D plot via rgl
  rgl_gaussian_2D(gauss_data)


  #### Example 2: Constrained elliptical_log ####
  ## This fits a constrained elliptical, as in Priebe et al. 2003
  gauss_fit <-
    fit_gaussian_2D(
      samp_dat,
      method = "elliptical_log",
      constrain_orientation = -1
    )

  ## Generate a grid of x- and y- values on which to predict
  grid <-
    expand.grid(X_values = seq(from = -5, to = 0, by = 0.1),
                Y_values = seq(from = -1, to = 4, by = 0.1))

  ## Predict the values using predict_gaussian_2D
  gauss_data <-
    predict_gaussian_2D(
      fit_object = gauss_fit,
      X_values = grid$X_values,
      Y_values = grid$Y_values,
    )

  ## Plot via ggplot2 and metR
  ggplot_gaussian_2D(gauss_data)

  ## Produce a 3D plot via rgl
  rgl_gaussian_2D(gauss_data)
}

Example output



gaussplotR documentation built on Jan. 13, 2021, 3:55 p.m.