GG_scatter: Scatter plot with regression line and correlation information...

View source: R/plotting.R

GG_scatterR Documentation

Scatter plot with regression line and correlation information using ggplot2

Description

Plots a scatterplot with a regression line and correlation information. Returns a ggplot2 object.

Usage

GG_scatter(
  df,
  x_var,
  y_var,
  weights = NULL,
  color = NULL,
  se = T,
  alpha = 1,
  text_pos = NA,
  case_names = NULL,
  case_names_color = "black",
  CI = 0.95,
  clean_names = T,
  check_overlap = T,
  repel_names = F,
  weight_as_size = T,
  ...
)

Arguments

df

(data.frame) A data frame with variables.

x_var

(chr scalar) X variable string.

y_var

(chr scalar) Y variable string.

weights

(num scalar) A set of weights to use.

color

(chr) A variable to color points by.

alpha

(num) The alpha to use.

text_pos

(chr scalar) Where to put the text. Defaults to top left ("tl") if correlation is positive, or tr if negative. Can be tl, tr, bl, or br.

case_names

(lgl scalar) Whether to add case names or not (default true).

case_names_color

(lgl scalar) Color of case names.

CI

(num scalar) Confidence interval as a fraction.

clean_names

(lgl scalar) Whether to clean the axes names using str_clean().

check_overlap

(lgl scalar) Whether to avoid overplotting names.

repel_names

(lgl) If using case names, should they be repelled?

weight_as_size

(lgl scalar) Whether to resize points by the weights.

...

Details

Internally uses the ad hoc variables .weights, .label and .color. If you name your variables these, then you will get odd problems.

Examples

GG_scatter(iris, "Sepal.Length", "Sepal.Width") #default plot
GG_scatter(iris, "Sepal.Length", "Sepal.Width", se = F) #no SE ribbon
GG_scatter(iris, "Sepal.Length", "Sepal.Width", case_names = rep("A", 150)) #case names
GG_scatter(iris, "Sepal.Length", "Sepal.Width", case_names = "Species") #case names from variable
GG_scatter(iris, "Sepal.Length", "Sepal.Width", case_names = "Species", case_names_color = "purple") #case names in purple
GG_scatter(iris, "Sepal.Length", "Sepal.Width", case_names = "Species", repel_names = T) #case names from variable, repelled
GG_scatter(iris, "Sepal.Length", "Sepal.Width", text_pos = "br") #other text location
GG_scatter(iris, "Sepal.Length", "Sepal.Width", CI = .99) #other CI
GG_scatter(iris, "Sepal.Length", "Sepal.Width", clean_names = F) #don't clean names
GG_scatter(iris, "Sepal.Length", "Sepal.Width", weights = 1:150) #add weights with vector
GG_scatter(iris, "Sepal.Length", "Sepal.Width", weights = "Petal.Width") #add weights with name
GG_scatter(iris, "Sepal.Length", "Sepal.Width", weights = 1:150, weight_as_size = F) #add weights with vector but don't resize
GG_scatter(iris, "Sepal.Length", "Sepal.Width", color = "Species") #color points
GG_scatter(iris, "Sepal.Length", "Sepal.Width", color = "Species", case_names = "Species") #color points, but labels stay black
GG_scatter(iris, "Sepal.Length", "Sepal.Width", alpha = .1) #change alpha

Deleetdk/kirkegaard documentation built on June 7, 2024, 7:49 a.m.