gg_scatter: Scatter plots

Description Usage Arguments Details Value Author(s) Examples

Description

Creates a scatter plot

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
gg_scatter(data, x, y, label = NULL, facet_r = NULL, facet_c = NULL,
  facet_r_levels = NULL, facet_c_levels = NULL, facet_scale = "free",
  facet_space = "free", color_var = NULL, all_colors = NULL,
  color_lab = color_var, shape_var = NULL, all_shapes = NULL,
  shape_lab = shape_var, add_label = FALSE, is_repel = FALSE,
  label_xlim = c(-Inf, Inf), label_ylim = c(-Inf, Inf),
  label_xloc = "middle", label_yloc = "middle", x_lab = x, y_lab = y,
  title = "", x_limit = NULL, y_limit = NULL, x_log = FALSE,
  y_log = FALSE, add_legend = TRUE, legend_pos = "bottom",
  reference_hline = NULL, reference_vline = NULL, smooth_line = NULL,
  smooth_line_ci = FALSE, bw_theme = TRUE, grids = "on")

Arguments

data

Data frame: default dataset to use for plot

x

Character: name of a data column mapped to x-axis variable, i.e. time

y

Character: name of a data column mapped to y-axis variable

label

Character: name of a data column mapped to point labels

facet_r

Character: name of a data column mapped to the facet row in panel plot layout. Check facet_grid for more details

facet_c

Character: name of a data column mapped to the facet column in panel plot layout. Check facet_grid for more details

facet_r_levels

Vector/List: a named vector/list that specifies the levels and labels of facet_r

facet_c_levels

Vector/List: a named vector/list that specifies the levels and labels of facet_c

facet_scale

Character: Are scales shared across all facets. Refer to the 'scale' argument in facet_grid. Default 'free' means that scales are not shared

facet_space

Character: Refer to the 'space' argument in facet_grid. Default 'free' means both height and width will vary

color_var

Character: name of a data column mapped to the color of the points

all_colors

Vector: a vector of valid color representations for all the point colors. See is.color for valid color definition

color_lab

Character: title of color legend

shape_var

Character name of a data column mapped to the shape of the points

all_shapes

Vector: a vector of all the point shapes. See ggplot2 Quick Reference: shape

shape_lab

Character: title of shape legend

add_label

Logical: whether or not to add labels for the points Default is set to 'FALSE'

is_repel

Logical: whether or not to avoid text overlapping using ggrepel

label_xlim

Numeric vector of length 2: it defines x-axis range to select points for labelling. See label_xloc for more details of point labelling rule. Default 'c(-Inf, Inf)' includes all the points over x-axis

label_ylim

Numeric vector of length 2: it defines y-axis range to select points for labelling. See label_yloc for more details of point labelling rule. Default 'c(-Inf, Inf)' includes all the points over x-axis

label_xloc

Character: Either 'middle' or 'sides'. Together with label_xlim, it defines the rule of point labelling. Only points, whose x-axis coordinates fall within (if 'middle') or beyond (if 'sides') the x-axis range defined by label_xlim, are to be labelled.

label_yloc

Character: Either 'middle' or 'sides'. Together with label_ylim, it defines the rule of point labelling. Only points, whose y-axis coordinates fall within (if 'middle') or beyond (if 'sides') the y-axis range defined by label_ylim, are to be labelled.

x_lab

Character: x-axis label

y_lab

Character: y-axis label

title

Character: barplot title

x_limit

Numeric vector of length 2: limits for x-axis, e.g. c(0, 10).

y_limit

Numeric vector of length 2: limits for y-axis, e.g. c(-5, 5)

x_log

Logical: whether or not to use log scale for x-axis. Default is set to 'TRUE'

y_log

Logical: whether or not to use log scale for y-axis. Default is set to 'TRUE'

add_legend

Logical: TRUE (default) to show legend and FALSE otherwise

legend_pos

Character: dictates the location where to place the legend. By default, the legend will be place beneath the actual plot

reference_hline

Numeric vector: locations of horizontal reference line(s) if there is any

reference_vline

Numeric vector: locations of vertical reference line(s) if there is any

smooth_line

Character: smoothing line type to be added to the points. Valid smoothing line types include 'NULL' (default), "identity", "lm", "glm", "gam", "loess", "rlm". See also 'method' argument in geom_smooth. When 'NULL', no line is added

smooth_line_ci

Logical: display confidence interval around smooth. By default ('FALSE'), confidence interval is not displayed

bw_theme

Logical: If 'TRUE' (default), black-and-white theme will be used. Refer to theme_bw for more details

grids

Character: grids option. Must be one of ‘c(’on', 'major', 'off')‘ with ’on' having both major and minor grids, 'major' having only major grids, and 'off' having no grids

Details

This function relies on ggplot2 package to create a scatter plot with ability to label points within specific region. Point labelling has the option to repel text overlapping with ggrepel. The function supports panel plot layout. By default black-and-white theme is used.

Value

An object of class ggplot. Can be directly sent to plot with print

Author(s)

Feiyang Niu (Feiyang.Niu@gilead.com)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
data <- mtcars
data$model <- row.names(data)
data$cyl <- factor(data$cyl)
gg_scatter(data, x = 'wt', y = 'mpg', label = 'model', color_var = 'cyl',
           color_lab = 'Cylinder', add_label = TRUE, is_repel = TRUE,
           label_xlim = c(2, 5), label_xloc = 'sides',
           x_lab = 'Weight (1000 lbs)', y_lab = 'Miles/(US) gallon')

gg_scatter(data, x = 'wt', y = 'mpg', label = 'model', facet_c = 'cyl',
           facet_c_levels = c('4 Cylinders' = '4', '6 Cylinders' = '6',
                              '8 Cylinders' = '8'),
           add_label = TRUE, is_repel = TRUE,
           x_lab = 'Weight (1000 lbs)', y_lab = 'Miles/(US) gallon')

statech/CommonPlots documentation built on May 6, 2019, 1:32 a.m.