View source: R/bcat_plt_point.R
| bcat_plt_point | R Documentation |
Create a scatter plot using ggplot2 graphics. This function is a wrapper to create commonly used styles of scatter plots. Additional layers can be added to this plot as needed. More complicated scatter plots can be creating using individual ggplot2 layers.
bcat_plt_point(
df,
x,
y,
color = NULL,
size = NULL,
facet = NULL,
jitter = FALSE,
jitter_width = NULL,
smooth = FALSE,
method = "lm",
se = TRUE,
x_lab = ggplot2::waiver(),
y_lab = ggplot2::waiver(),
title = ggplot2::waiver(),
subtitle = ggplot2::waiver(),
caption = ggplot2::waiver(),
legend_lab = ggplot2::waiver(),
legend_position = "bottom",
legend_hide = FALSE,
x_scale = NULL,
y_scale = NULL,
color_scale = Rbearcat::scale_colour_UC(),
fill_scale = Rbearcat::scale_fill_UC(),
facet_scale = c("fixed", "free_y", "free_x", "free"),
alpha = 0.6,
nrow = NULL,
ncol = NULL,
x_refline = NULL,
y_refline = NULL,
identity_line = FALSE,
x_highlight_min = NULL,
x_highlight_max = NULL,
y_highlight_min = NULL,
y_highlight_max = NULL,
y_error_min = NULL,
y_error_max = NULL,
y_error_width = 1
)
df |
The data to be displayed |
x |
Variable to map to the x-axis |
y |
Variable to map to the y-axis |
color |
Variable to map to the color aesthetic |
size |
Variable to map to the size aesthetic |
facet |
Facetting variable(s). Note: must wrap in |
jitter |
Set to |
jitter_width |
Set the jitter width. Leave as |
smooth |
Add fit line to plot |
method |
Method to use for fit line. "lm" is default |
se |
Set to |
x_lab |
Label for x-axis |
y_lab |
Label for y-axis |
title |
Plot title |
subtitle |
Plot subtitle |
caption |
Plot caption |
legend_lab |
Legend title |
legend_position |
legend position. "bottom" or "right" |
legend_hide |
Set to |
x_scale |
|
y_scale |
|
color_scale |
|
fill_scale |
|
facet_scale |
Shoud facet scales be fixed ("fixed", the default), free ("free"), or free in one dimension ("free_x", "free_y")? |
alpha |
level of point transparency. lower alpha leads to more transparency. |
nrow |
Number of facet rows |
ncol |
Number of facet columns |
x_refline |
Vector of x-values at which to draw vertical reference lines |
y_refline |
Vector of y-values at which to draw horizontal reference lines |
identity_line |
Set to |
x_highlight_min |
Vector of min x-values at which to start draw rectangle annotation |
x_highlight_max |
Vector of max x-values at which to end rectangle annotation |
y_highlight_min |
Vector of min y-values at which to start draw rectangle annotation |
y_highlight_max |
Vector of max y-values at which to end rectangle annotation |
y_error_min |
Variable to use as minimum values for error bars around y at each value of x |
y_error_max |
Variable to use as maximum values for error bars around y at each value of x |
y_error_width |
Width of error bars |
A ggplot2 plot object.
Saannidhya Rawat
Other plots:
bcat_plt_area(),
bcat_plt_bar(),
bcat_plt_box(),
bcat_plt_coef(),
bcat_plt_diag(),
bcat_plt_hist(),
bcat_plt_line(),
bcat_plt_ts()
library(ggplot2)
# basic scatter plot
bcat_plt_point(df = iris,
x = Sepal.Length,
y = Sepal.Width,
x_lab = "Length",
y_lab = "Width",
title = "Sepal Width vs Length")
# scatter plot with LOESS fit line
bcat_plt_point(df = iris,
x = Sepal.Length,
y = Sepal.Width,
x_lab = "Length",
y_lab = "Width",
smooth = TRUE,
method = "loess",
title = "Sepal Width vs Length",
subtitle = "Loess Fit")
# scatter plot with faceting and LM fit lines
bcat_plt_point(df = iris,
x = Sepal.Length,
y = Sepal.Width,
color = Species,
facet = vars(Species),
smooth = TRUE,
x_lab = "Length",
y_lab = "Width",
legend_lab = NULL,
title = "Sepal Width vs Length by Species",
subtitle = "Linear Fit",
nrow = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.