View source: R/zzz-r4vn-graphs.R View source: R/graphs.R
| gscatter | R Documentation |
Draws the relationship between two numeric variables, optionally colored by a group and with fitted lines.
gscatter(
data = NULL, x, y = NULL, vars = NULL, by = NULL, fit = FALSE,
fit_color = NULL, fit_lty = 1, fit_lwd = 2, cor = FALSE, pch = 16,
point_size = 1, xlab = NULL, ylab = NULL, xtitle = NULL, ytitle = NULL,
xbreaks = NULL, ybreaks = NULL, title = NULL, subtitle = NULL, note = NULL,
color = NULL, palette = "default", alpha = 0.75, legend = TRUE,
legend_position = "topright", xline = NULL, yline = NULL,
ref_color = "gray40", ref_lty = 2, ref_lwd = 1, theme = "journal",
size = 11, combine = FALSE, ncol = NULL, file = NULL, width = 7, height = 5,
dpi = 300, show = TRUE, bg = "white", vline = NULL, hline = NULL
)
data |
A data frame. It may be omitted when an active R4VN data frame exists. |
x |
Categorical variable on the horizontal axis. Supply an unquoted name or a character name. |
y |
Optional numeric variable. When omitted, bars show counts or percentages. When supplied, bars show a mean or median. |
vars |
Optional |
by |
Optional grouping variable or hierarchical |
fit |
|
fit_color, fit_lty, fit_lwd |
Colour, line type, and line width for the fitted line. |
cor |
Add the Pearson correlation coefficient to the graph. |
pch |
Point symbol. |
point_size |
Point-size multiplier. |
xlab |
Optional category labels. Use an unnamed vector in displayed order or a named vector such as |
ylab |
Optional y-axis tick labels. |
xtitle, ytitle |
Axis titles. Variable names or variable labels are used automatically when possible. |
xbreaks, ybreaks |
Numeric tick positions used with |
title, subtitle, note |
Main title, subtitle, and note. |
color |
A color name or vector of colors. When |
palette |
One of |
alpha |
Color opacity from 0 to 1. |
legend |
Show the legend when |
legend_position |
Base-R legend position, for example |
xline, yline |
Optional numeric reference lines on the x and y axes.
Thus |
ref_color, ref_lty, ref_lwd |
Color, line type, and width for reference lines; vectors are recycled for multiple lines. |
theme |
Graph theme: |
size |
Base font size. |
combine |
When several graphs are produced, draw them as labelled panels in one figure. |
ncol |
Optional number of columns in a combined figure. |
file |
Optional output file ending in png, jpg, tiff, pdf, or svg. |
width, height |
Output width and height in inches. |
dpi |
Resolution for raster output. |
show |
Draw the graph in the current graphics device. |
bg |
Background color for exported files. |
vline, hline |
Deprecated aliases for |
Draws one x variable against one or several y variables. Hierarchical by
uses all but the last variable as strata and the last variable as the plotted
grouping variable.
An object of class r4vn_graph; its data component contains complete plotted observations.
d <- data.frame(
age = c(22, 28, 35, 41, 55),
bmi = c(20, 23, 25, 27, 29),
sex = c("M", "F", "F", "M", "F")
)
gscatter(d, x = age, y = bmi)
gscatter(d, x = age, y = bmi, by = sex, fit = "linear", cor = TRUE)
# Extended usage examples
d <- data.frame(age = c(22, 28, 35, 41, 55),
bmi = c(20, 23, 25, 27, 29),
sex = c("M", "F", "F", "M", "F"))
gscatter(d, x = age, y = bmi, show = FALSE)
gscatter(d, x = age, y = bmi, fit = "linear", cor = TRUE, show = FALSE)
gscatter(d, x = age, y = bmi, by = sex, fit = "linear", show = FALSE)
gscatter(d, x = age, y = bmi, fit = "loess", show = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.