Skip to content

Commit

Permalink
dfgdgd
Browse files Browse the repository at this point in the history
  • Loading branch information
svmiller committed Jan 30, 2025
1 parent 2d18a8f commit afb619a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions R/linloess_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
#' @param suppress_warning logical, defaults to \code{TRUE}. If \code{TRUE},
#' the plot suppresses assorted warnings from the LOESS smoother that would
#' otherwise be cautioning you about things your eyes could otherwise see.
#' @param no_dummies logical, defaults to \code{FALSE}. If \code{TRUE}, removes
#' binary independent variables from the plot. If \code{FALSE}, facets appear for
#' binary independent variables. You should probably just set this to \code{TRUE}
#' for your own use cases.
#' @param ... optional parameters, passed to the scatterplot in \code{linloess_plot()}
#' (\code{geom_point()}) component of this function. Useful if you want to make
#' the smoothers more legible against the points.
Expand All @@ -62,10 +66,17 @@
#'
linloess_plot <- function(mod, resid = TRUE, smoother = "loess",
se = TRUE, span = .75,
no_dummies = FALSE,
suppress_warning = TRUE, ...) {

modframe <- model.frame(mod)

if(no_dummies == TRUE) {

modframe <- modframe[, sapply(modframe, function(col) length(na.omit(unique(col)))) > 2]

}

if(resid == FALSE) {

dat <- gather(modframe, "var", "value", 2:ncol(modframe))
Expand All @@ -78,9 +89,9 @@ linloess_plot <- function(mod, resid = TRUE, smoother = "loess",
# scatterplot
geom_point(...) +
# linear smoother
geom_smooth(method="lm", fill="blue", se = se) +
geom_smooth(method="lm", fill="black", color='black', se = se) +
# smoother, with different color
geom_smooth(method = smoother, color = "black", linetype = "dashed",
geom_smooth(method = smoother, color = "blue", linetype = "dashed",
se = se, span = span) -> plot

} else {
Expand All @@ -97,9 +108,9 @@ linloess_plot <- function(mod, resid = TRUE, smoother = "loess",
# scatterplot
geom_point(...) +
# linear smoother
geom_smooth(method="lm", fill="blue", se = FALSE) +
geom_smooth(method="lm", color="black", linetype = 'dashed', se = FALSE) +
# smoother, with different color
geom_smooth(method = smoother, color = "black", linetype = "dashed",
geom_smooth(method = smoother, color = "blue",
se = se, span = span) -> plot
}

Expand All @@ -115,7 +126,7 @@ linloess_plot <- function(mod, resid = TRUE, smoother = "loess",
#' Print method for class 'linloess'
#'
#' @param x a ggplot object with this special 'linloess' class
#' @param ... Additional arguments in the context of the print function (not used)
#' @param ... Additional arguments (passed to the scatterplot in \code{linloess_plot()}, not used in the print function
#' @keywords internal
#' @rdname linloess_plot
#' @export
Expand Down

0 comments on commit afb619a

Please sign in to comment.