Skip to contents

plot_scatter() creates a pre-themed scatterplot on two variables, optionally grouped by a third categorical variable.

Usage

plot_scatter(
  data,
  formula,
  fill = "#0032a0",
  title = NULL,
  legend_title = NULL,
  axis_lines = c("none", "both"),
  ls_line = c("hide", "show"),
  ...
)

Arguments

data

A data frame.

formula

Variables to build the plot on. Should be entered in formula notation, var1~var2.

fill

The fill of the plot. Valid options are a character color (for standard scatterplots) or a variable given in formula notation (~var), used to create a grouped scatterplot.

title

An override for the title of the plot. A sensible default is provided.

legend_title

The title of the lengend. Ignored in non-grouped plots. Default is the variable name.

axis_lines

Should major axis lines appear on the plot? Valid options are "none" or "both. Defaults to "none".

ls_line

Should a least squares line (or lines) appear on the plot? Defaults to "hide".

...

Extra title arguments passed on to ggformula::gf_labs() (which feeds to ggplot2::ggplot()).

Value

A ggplot object. In an interactive environment, results are viewable immediately.

Examples

plot_scatter(mtcars, wt~drat)
#> Note: NAs always removed (in pairs) for scatterplots.
#> This message is displayed once every 8 hours.

plot_scatter(mtcars, wt~drat, fill = "red")

plot_scatter(mtcars, wt~drat, axis_lines = "both")

plot_scatter(mtcars, wt~drat, ls_line = "show")


plot_scatter(mtcars, wt~drat, fill = ~cyl)

plot_scatter(mtcars, wt~drat, fill = ~cyl, ls_line = "show")

plot_scatter(mtcars, wt~drat, fill = ~cyl, legend_title = "Cylinders")