ggpmisc 0.4.7

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 {
      mf
   }
}

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 = 2)

Which produces the figure below, 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:

  • Fix bug in the handling of the weight aesthetic in some of the model fitting statistics.
  • The model formula is in calls to stat_poly_eq() and stat_quant_eq() now retrieved from the returned fitted model object. This makes it possible model selection within the function passed as argument to method. (Inspired by an answer read in Stackoverflow.)
  • Statistics now search for a matching function when an arbitrary name is supplied as a character string argument to parameter method.
  • The character string passed as argument to parameter method is now parsed so that it can contain both the name of a model fit function and the argument to be passed to this function’s own method parameter. (Backward compatibility is maintained.)
  • The stats that create equation labels now include a variable method in the returned data containing a character string with the method used in the model fit.

Documentation web site at http://docs.r4photobiology.info/ggpmisc/ 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 https://github.com/aphalo/ggpmisc/issues

ggpmisc 0.4.6

Version 0.4.6 fixes a significant bug occasionally affecting highlighting and labelling of peaks and valleys. Even though when triggered the problem is easily detectable by looking at the plot, please, update.

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

  • Fix bug in stat_peaks() and stat_valleys(). They could return wrong values for peaks and valleys if the rows in data in the ggplot object were not sorted by the value of x.

Documentation web site at http://docs.r4photobiology.info/ggpmisc/ includes all help pages, with output from all examples, vignettes as well as a changelog in HTML format.

NOTE: Version 0.4.6 is on its way to CRAN.

Please raise issues concerning bugs or enhancements to this package through GitHub https://github.com/aphalo/ggpmisc/issues

ggpmisc 0.4.5

Version 0.4.5 includes a minor bugfix and an edit in vignette examples, to ensure compatibility with the upcoming version of package ‘ggpp’.

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

  • Decrease version of ‘gginnards’ in suggests.
  • Edit vignette examples to allow renaming a geom exported by ‘ggpp’ (retaining backwards compatibility).

Documentation web site at http://docs.r4photobiology.info/ggpmisc/ includes all help pages, with output from all examples, vignettes as well as a changelog in HTML format.

NOTE: Version 0.4.5 is on its way to CRAN.

Please raise issues concerning bugs or enhancements to this package through GitHub https://github.com/aphalo/ggpmisc/issues

ggpmisc 0.4.4

Version 0.4.4 includes enhancements. An issue raised in GitHub and a question in StackOverflow asked for the possibility of changing how fitted lines are plotted based on the “goodness” of the fit. In addition an old question in StackOverflow highlighted the need of more intuitive support for annotations based on stats::cor.test(). In addition to implementing these enhancements we continued adding support for flipping of statistics controlled through formal parameter orientation as implemented in ‘ggplot2’ since version 3.3.0.

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

  • Add new function stat_correlation() to annotate plots with correlation estimates, their P-value, a test statistic and n computed with stats::cor.test(). In addition to formatted character strings, numeric values are included in the returned data frame to facilitate conditional display.
  • Update stat_poly_line() to optionally add columns n, p.value, r.squared , adj.r.squared and method to the returned data frame. Code breaking: This statistic no longer supports fitting of splines with methods such as loess . This could potentially break user code, in which case the solution is to use stat_smooth().
  • Update stat_ma_line() to optionally add columns n, p.value, r.squared and method to the returned data frame. (As only a slope can be fitted, adj.r.squared is irrelevant.)
  • Update stat_quant_line() and stat_quant_band() to optionally add n and method columns to the returned data frame. (No exact equivalent of r.squared exists for quantile regression.)
  • Update stat_fit_residuals() to optionally return weighted
    residuals.
  • Update stat_peaks() and stat_valleys() to allow flipping with new parameter orientation.

Documentation web site at http://docs.r4photobiology.info/ggpmisc/ includes all help pages, with output from all examples, vignettes as well as a changelog in HTML format.

NOTE: Version 0.4.4 is on its way to CRAN.

Please raise issues concerning bugs or enhancements to this package through GitHub https://github.com/aphalo/ggpmisc/issues