ggpmisc 0.4.7

R Package Update

Pedro J. Aphalo






ggpmisc pkg

Version 0.4.7 brings a fix for a bug that could prevent the use of weights passed through aesthetic weight in some of the model-fitting statistics. Several enhancements to the model fitting statistics make it easier to fit different models to different groups or panels, and make it possible/easier to select among methods supported by a model fit function.

Here is a simple example of fitting different models to different panels. Instead of using lm() as method, we define a wrapper function that tests for the significance of the slope in linear regression, and if not significant, fits the mean instead.

poly_or_mean <- function(formula, data, ...) {
  mf <- lm(formula = formula, data = data, ...)
  if (anova(mf)[["Pr(>F)"]][1] > 0.1) {
    lm(formula = y ~ 1, data = data, ...)
  } else {

We pass the name of this function as argument to method overriding the default argument "lm".

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  stat_poly_line(method = "poly_or_mean") +
  stat_poly_eq(method = poly_or_mean,
               aes(label = after_stat(eq.label)),
               label.x = "right") +
  theme(legend.position = "bottom") +
  facet_wrap(~class, ncol = 4)

Which produces the figure above, showing the mean in panels 2seater and minivan, and a linear regression in others.

Aditional examples are available in the free supplementary chapters of my book Learn R: As a Language.

Changes compared to version 0.4.6, the previous version in CRAN are:

Documentation web site at includes all help pages, with output from all examples, vignettes as well as a changelog in HTML format.

NOTE: Version 0.4.7 is on its way to CRAN.

Please raise issues concerning bugs or enhancements to this package through GitHub