R/plot_data.R

Defines functions plot_data

Documented in plot_data

#This function will plot regression lines.
plot_data<-function(dep_var,indep_var,dat)
{
  #Check whether dep_var and indep_var are in dat
  if (deparse(substitute(dep_var)) %in% colnames(dat) & deparse(substitute(indep_var)) %in% colnames(dat)){
  xaes<-dat[[deparse(substitute(indep_var))]]
  yaes<-dat[[deparse(substitute(dep_var))]]
  #check whether provided variables are continuous
  if ((class(yaes) =="numeric" | class(yaes)=="integer") & (class(xaes) =="numeric" | class(xaes)=="integer"))
  {
  #create plot
  g1<-ggplot(data=dat,aes(y=yaes,x=xaes))+labs(x=deparse(substitute(indep_var)),y=deparse(substitute(dep_var)))+geom_point(shape=1,size=2.3)+geom_smooth(method="lm",se=FALSE)
  g1

  } else
  {
      cat("Error: Dependent and Independent Variable must be continuous.")
  }
  }
  else{
    cat("Error: Check variable names.")
  }
}
wilart/wilprocr documentation built on May 28, 2017, 3:19 a.m.