img_plot: Image Plot

Description Usage Arguments Value Examples

Description

Create a scatterplot with biologically relevant glyphs.

Usage

1
2
3
img_plot(main_plot, y_breaks = 11, y_labels = 0:10, img_type,
  n_img = NULL, img_positions = "uniform", peaks_adjust = 0,
  img_range = NULL, img_height = NULL)

Arguments

main_plot

The main scatterplot as a ggplot object. It must contain a smoothing function as returned by geom_smooth() or stat_smooth().

y_breaks

Either a numeric vector of two or more unique cut points (points along the y-axis) or a single number (greater than or equal to 2) giving the number of intervals into which the y axis is to be cut (providing a uniform number of cuts along the y axis). This will create the intervals which the images will be defined across.

y_labels

The image levels of the resulting y_breaks intervals. The number of y_labels must be the same as the number of y_breaks. Currently the maximum number of breaks and labels is 11, so 'y_labels = 0:10' is suggested with 'y_breaks = 11'.

img_type

The type of image plot you need. A character string of either "strength" or "hydration".

n_img

An integer of the number of images you want below the x-axis. Defaults to length(x-axis) / 20. Ignored if supplying a numeric vector for 'img_positions'.

img_positions

Defines the image placement under the x-axis. A character string of either "uniform", "peaks", or a user supplied integer vector of x-axis indices. Defaults to "uniform".

peaks_adjust

An integer to adjust the window width for the argument setting: img_positions = "peaks". Positive values increase the window width (less sensitive to local minima and maxima). Negative values decrease the window width (more sensitive to local minima and maxima).

img_range

An integer to adjust the range of values that are used to calculate the mean y-value and it's corresponding image (based on the fitted smooth curve). For example, the "uniform" img_positions method defaults to using all y-values in each y_interval, the "peaks" img_positions method defaults to a range of 0, and supplying your own img_positions values will default to a range of 5.

img_height

An integer setting the number of rows (height) for the image plots. Defaults is 2.

Value

Returns an image plot grob as a ggplot2 grob object.

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
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
## Not run: 
#----------------------------------------------------------------------------
# img_plot example
#----------------------------------------------------------------------------
library(imgplot)

#-------------------------------------------------------------------------------
# Create example data.
#-------------------------------------------------------------------------------
set.seed(1)
n <- 80
x1 = sample(LETTERS[c(1, 3, 7, 20)], size = n, replace = TRUE)
x2 = sample(LETTERS[c(1, 3, 7, 20)], size = n, replace = TRUE)
y <- sin(2 * pi * seq_along(x1) / n) + runif(length(x1), -1, 1)
data <- data.frame(
  a = x1,
  c = x2,
  b = y,
  stringsAsFactors = FALSE
)
main_plot <- ggplot(data, aes(1:length(x1), b)) +
  geom_point() +
  theme_bw() +
  geom_smooth(method = "loess", span = 0.7) +
  scale_x_continuous(
    name = "Pairwise Sequence Alignment",
    breaks = 1:length(data$a),
    labels = paste0(data$a, "\n", data$c)
  )
main_plot

#-------------------------------------------------------------------------------
# Uniform - Strength
#-------------------------------------------------------------------------------
plot <- img_plot(
  main_plot = main_plot,
  y_breaks = 11,
  y_labels = 0:10,
  img_type = "strength",
  n_img = 9,
  img_positions = "uniform"
)

#-------------------------------------------------------------------------------
# Peaks - Strength
#-------------------------------------------------------------------------------
plot <- img_plot(
  main_plot = main_plot,
  y_breaks = 11,
  y_labels = 0:10,
  img_type = "strength",
  n_img = 9,
  img_positions = "peaks"
)

#-------------------------------------------------------------------------------
# Manual positioning - Strength
#-------------------------------------------------------------------------------
plot <- img_plot(
  main_plot = main_plot,
  y_breaks = 11,
  y_labels = 0:10,
  img_type = "strength",
  img_positions = c(20, 60)
)

#-------------------------------------------------------------------------------
# Uniform - Hydration
#-------------------------------------------------------------------------------
plot <- img_plot(
  main_plot = main_plot,
  y_breaks = 11,
  y_labels = 0:10,
  img_type = "hydration",
  n_img = 9,
  img_positions = "uniform",
)

#-------------------------------------------------------------------------------
# Peaks - Hydration
#-------------------------------------------------------------------------------
plot <- img_plot(
  main_plot = main_plot,
  y_breaks = 11,
  y_labels = 0:10,
  img_type = "hydration",
  n_img = 9,
  img_positions = "peaks"
)

#-------------------------------------------------------------------------------
# Manual positioning - Hydration
#-------------------------------------------------------------------------------
plot <- img_plot(
  main_plot = main_plot,
  y_breaks = 11,
  y_labels = 0:10,
  img_type = "hydration",
  img_positions = c(20, 60)
)

## End(Not run)

cwbartlett/manogram documentation built on May 8, 2019, 9:20 a.m.