Description Usage Arguments Details Value Author(s) Examples
Creates a scatter plot
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")
|
data |
Data frame: default dataset to use for plot |
x |
Character: name of a |
y |
Character: name of a |
label |
Character: name of a |
facet_r |
Character: name of a |
facet_c |
Character: name of a |
facet_r_levels |
Vector/List: a named vector/list that specifies the
levels and labels of |
facet_c_levels |
Vector/List: a named vector/list that specifies the
levels and labels of |
facet_scale |
Character: Are scales shared across all facets. Refer to
the 'scale' argument in |
facet_space |
Character: Refer to the 'space' argument in
|
color_var |
Character: name of a |
all_colors |
Vector: a vector of valid color representations for all
the point colors. See |
color_lab |
Character: title of color legend |
shape_var |
Character name of a |
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_ylim |
Numeric vector of length 2: it defines y-axis range to
select points for labelling. See |
label_xloc |
Character: Either 'middle' or 'sides'. Together with
|
label_yloc |
Character: Either 'middle' or 'sides'. Together with
|
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.
|
y_limit |
Numeric vector of length 2: limits for y-axis, e.g.
|
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: |
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
|
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 |
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 |
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.
An object of class ggplot. Can be directly sent to plot with
print
Feiyang Niu (Feiyang.Niu@gilead.com)
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')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.