Skip to contents

Creates interactive scatter plots showing relationships between two continuous variables. Supports optional color grouping, custom sizing, and trend lines.

Usage

viz_scatter(
  data,
  x_var,
  y_var,
  color_var = NULL,
  size_var = NULL,
  title = NULL,
  subtitle = NULL,
  x_label = NULL,
  y_label = NULL,
  color_palette = NULL,
  point_size = 4,
  show_trend = FALSE,
  trend_method = "lm",
  alpha = 0.7,
  include_na = FALSE,
  na_label = "(Missing)",
  tooltip = NULL,
  tooltip_format = NULL,
  jitter = FALSE,
  jitter_amount = 0.2
)

Arguments

data

A data frame containing the data.

x_var

Character string. Name of the variable for the x-axis (continuous or categorical).

y_var

Character string. Name of the variable for the y-axis (continuous).

color_var

Optional character string. Name of grouping variable for coloring points.

size_var

Optional character string. Name of variable to control point sizes.

title

Optional main title for the chart.

subtitle

Optional subtitle for the chart.

x_label

Optional label for the x-axis. Defaults to x_var name.

y_label

Optional label for the y-axis. Defaults to y_var name.

color_palette

Optional character vector of colors for the points.

point_size

Numeric. Default size for points when size_var is not specified. Defaults to 4.

show_trend

Logical. Whether to add a trend line. Defaults to FALSE.

trend_method

Character string. Method for trend line: "lm" (linear) or "loess". Defaults to "lm".

alpha

Numeric between 0 and 1. Transparency of points. Defaults to 0.7.

include_na

Logical. Whether to include NA values in color grouping. Defaults to FALSE.

na_label

Character string. Label for NA category if include_na = TRUE. Defaults to "(Missing)".

tooltip

A tooltip configuration created with tooltip(), OR a format string with {placeholders}. Available placeholders: {x}, {y}, {name}, {series}. See tooltip for full customization options.

tooltip_format

Character string. Custom format for tooltips using Highcharts placeholders like {point.x}, {point.y}. For the simpler dashboardr placeholder syntax, use the tooltip parameter instead.

jitter

Logical. Whether to add jittering to reduce overplotting. Defaults to FALSE.

jitter_amount

Numeric. Amount of jittering if jitter = TRUE. Defaults to 0.2.

Value

A highcharter plot object.

Examples

# Simple scatter plot
plot1 <- viz_scatter(
  data = mtcars,
  x_var = "wt",
  y_var = "mpg",
  title = "Car Weight vs MPG"
)
plot1
# Scatter plot with color grouping plot2 <- viz_scatter( data = iris, x_var = "Sepal.Length", y_var = "Sepal.Width", color_var = "Species", title = "Iris Sepal Measurements" ) plot2
# Scatter with trend line and custom colors plot3 <- viz_scatter( data = mtcars, x_var = "hp", y_var = "mpg", color_var = "cyl", show_trend = TRUE, title = "Horsepower vs MPG by Cylinders", color_palette = c("#FF6B6B", "#4ECDC4", "#45B7D1") ) plot3