pkgdown/extra.css

Skip to contents

plot_scatter_with_regression plots a scatter plot with a linear regression line. It is possible to add the standard error of the regression line, as well as the R-squared and p-value.

Usage

plot_scatter_with_regression(
  plot_data,
  x,
  y,
  se = FALSE,
  line_color = "black",
  r_2 = TRUE
)

Arguments

plot_data

The wide dataset containing the data to plot as cols.

x

The column name of the x-axis variable.

y

The column name of the y-axis variable.

se

Whether to add the standard error of the regression line. Default is FALSE.

line_color

The color of the regression line.

r_2

Whether to add the R-squared and p-value to the plot. Default is TRUE.

Value

The scatter plot with the regression line.

Examples

# Prepare the data
wide_data <- widen_data(example_data)

# Scatter plot for AARSD1 and ABL1
plot_scatter_with_regression(wide_data, "AARSD1", "ABL1", line_color = "red3")
#> `geom_smooth()` using formula = 'y ~ x'
#> Warning: Removed 34 rows containing non-finite outside the scale range
#> (`stat_smooth()`).
#> Warning: Removed 34 rows containing missing values or values outside the scale range
#> (`geom_point()`).