add_lines: Add lines with labels to pre-existing ggplot

View source: R/add_lines.R

add_linesR Documentation

Add lines with labels to pre-existing ggplot

Description

Add lines with labels to pre-existing ggplot

Usage

add_lines(
  p,
  df,
  xpos = 0.3,
  add.coord.fixed = TRUE,
  lty = NULL,
  color = NULL,
  size = 0.5,
  add_theme_bw2 = TRUE,
  ...
)

Arguments

p

An object of class ggplot

df

A data.frame. Required columns are slope, intercept and label

xpos

A numeric. Relative horizontal position

add.coord.fixed

Logical. Whether or not add coord_fixed() function

lty

line type

color

line color

size

line size

add_theme_bw2

logical Whether or not add theme_bw2()

...

Further arguments to be passed to geom_text

Examples

require(ggplot2)
fit=lm(mpg~wt*hp,data=mtcars)
df=calEquation(fit)
p=ggplot(data=mtcars,aes(x=wt,y=mpg))
add_lines(p,df)
add_lines(p,df,lty=1:3,color=1:3,size=1)
fit=lm(mpg~wt*vs,data=mtcars)
df=calEquation(fit)
p=ggplot(data=mtcars)+geom_point(aes(x=wt,y=mpg))
add_lines(p,df)
add_lines(p,df,lty=1:2,color=1:2,size=1)+theme_bw()

cardiomoon/predict3d documentation built on April 7, 2024, 10:26 p.m.