Skip to content

Commit

Permalink
qqplot can have same axes, and diagonal abline
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyDoorn committed Apr 10, 2024
1 parent 73e2e77 commit 94bb31e
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions R/plotQQnorm.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' jaspGraphs::plotQQnorm(x, lower, upper)
#'
#' @export
plotQQnorm <- function(residuals, lower = NULL, upper = NULL, abline = TRUE, ablineColor = "red",
plotQQnorm <- function(residuals, lower = NULL, upper = NULL, abline = TRUE, ablineColor = "red", plotDiagonal = FALSE, forceSameAxes = FALSE,
xName = gettext("Theoretical quantiles",domain="R-jaspGraphs"), yName = gettext("Observed quantiles",domain="R-jaspGraphs")) {

n <- length(residuals)
Expand Down Expand Up @@ -60,16 +60,31 @@ plotQQnorm <- function(residuals, lower = NULL, upper = NULL, abline = TRUE, abl
dfLine <- data.frame(x = xvals, y = yvals)
g <- ggplot2::ggplot(data = df, aes(x = .data$x, y = .data$y))

if (abline)
if (abline && plotDiagonal) {
g <- g + ggplot2::geom_line(data = data.frame(x = c(min(xvals), max(xvals)), y = c(min(xvals), max(xvals))),
mapping = ggplot2::aes(x = x, y = y),
col = "darkred",
size = 1)
} else if (abline) {
g <- g + ggplot2::geom_line(mapping = aes(x = .data$x, y = .data$y), data = dfLine, inherit.aes = FALSE, color = ablineColor)

}


if (hasErrorbars)
g <- g + ggplot2::geom_errorbar(aes(ymin = .data$ymin, ymax = .data$ymax))

g <- g +
geom_point() +
scale_x_continuous(name = xName, breaks = xBreaks) +
scale_y_continuous(name = yName, breaks = yBreaks)
if (forceSameAxes) {
axesBreaks <- union(xBreaks, yBreaks)
g <- g +
geom_point() +
scale_x_continuous(name = xName, breaks = axesBreaks) +
scale_y_continuous(name = yName, breaks = axesBreaks)
} else {
g <- g +
geom_point() +
scale_x_continuous(name = xName, breaks = xBreaks) +
scale_y_continuous(name = yName, breaks = yBreaks)
}

return(jaspGraphs::themeJasp(g))

Expand Down

0 comments on commit 94bb31e

Please sign in to comment.