ggxy: XY scatter plot wrapper

View source: R/fn_gg.R

ggxyR Documentation

XY scatter plot wrapper

Description

Create basic XY scatter plot for quick data exploration. Default to show Pearson correlation coefficient with p-value using ggpubr::stat_cor(). For more complex plots, it is recommended to use ggplot2::ggplot2 directly.

Usage

ggxy(
  d,
  x,
  y,
  ...,
  lm = TRUE,
  se = TRUE,
  cor = TRUE,
  pv = 0.001,
  nsub = TRUE,
  legend = TRUE,
  asp = 1
)

Arguments

d

⁠<dfr>⁠ A data frame.

x, y

⁠<var>⁠ Variables for x- and y-axis as unquoted names.

...

Arguments to pass to ggplot2::aes() for additional mapping.

lm

⁠<lgl>⁠ TRUE to add regression line from linear model.

se

⁠<lgl>⁠ TRUE to show standard error with the regression line.

cor

⁠<lgl>⁠ TRUE to show Pearson correlation coefficient with p-value.

pv

⁠<dbl>⁠ Precision of p-value, e.g., 0.001 to show 3 decimal places, NULL for no rounding.

nsub

⁠<lgl>⁠ Show number of observations.

legend

⁠<lgl>⁠ TRUE to show legend.

asp

⁠<num>⁠ For aspect.ratio in ggplot2::theme().

Value

A ggplot object.

See Also

ggpubr::stat_cor()

Examples

mtcars |> ggxy(wt,hp)
mtcars |> ggxy(wt,hp,col=factor(gear))
mtcars |> ggxy(wt,hp,col=factor(gear),legend=FALSE)
mtcars |> ggxy(wt,hp,col=factor(gear),pch=factor(am))
mtcars |> ggxy(wt,hp,nsub=FALSE)
mtcars |> ggxy(wt,hp,pv=NULL)
mtcars |> ggxy(wt,hp,lm=FALSE)
mtcars |> ggxy(wt,hp,se=FALSE)
mtcars |> ggxy(wt,hp,cor=FALSE)

edar documentation built on Nov. 15, 2026, 1:07 a.m.