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 {

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 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

photobiologyInOut 0.4.24

This non-code-breaking update brings a few new features and tracks deprecations in package ‘tidyr’.

The main changes from version 0.4.23 the previous CRAN release, are:

  • Replace use of deprecated tidyr::gather_().
  • Add function read_cid_spectravue_csv() supporting data import from measurements CSV files output by CID Bio-Science’s SpectraVue CI-710s leaf spectrometer.
  • Add function read_foreign2mspct() to apply an import function to a list of files.
  • Add color-related functions spct_CRI(), spct_CCT() and expect_SSI() implemented as wrappers to functions in package ‘colorSpec’. These functions accept source_spct objects as arguments. CRI, CCT and SSI are quantities used to describe light used for illumination, photography, cinematography and video.
  • Documentation web site at

NOTE: This version of the package is on its way to CRAN.

Please raise issues concerning bugs or enhancements to this package through Bitbucket at

ggspectra 0.3.8

Package documentation web site at:

Eighteen months from the previous release, this update brings many improvements to autoplot() methods. These include enhanced capabilities for handling of normalized and scaled spectral data, as well as cosmetic tweaks to labels.

This update also includes snaller enhancements and fixes a bug. It tracks changes in packages ‘ggrepel’ (>= 0.9.1), ‘photobiology’ (>= 0.10.10) and ‘ggplot2’ (>= 3.3.3) and deprecation of functions in ‘tidyr’ (>= 1.0.0). The updated code depends on the revised normalize() function in ‘photobiology’ (>= 0.10.10) and on ‘ggrepel’ (>= 0.9.1).

The changes from version 0.3.7, the current CRAN release, are:

  • Revise all autoplot() methods to support on-the-fly normalization internally using photobiology::normalize().
  • Revise autoplot() methods for source_spct, response_spct, filter_spct, reflector_spct, source_mspct, response_mspct, filter_mspct, and reflector_mspct so that if the data are already normalized, by default the normalization is updated according to the arguments passed to unit.out or plot.qty and range. (Update is possible only for objects normalized with ‘photobiology’ (\>= 0.10.7). For objects created with earlier versions, the old behaviour of plotting spectra as is remains unchanged.)
  • Revise autoplot() method for object_mspct to force use of facets when plot.qty = "all" instead of forcing plotting of transmittance only.
  • Revise autoplot() method for object_mspct to correctly handle normalization of collections of spectra, one spectrum at a time, correcting a bug.
  • Revise all autoplot() methods to generate shorter y-axis labels also improving reporting of scaling and normalization when needed.
  • Revise all autoplot() methods to fix bug leading to bad object name in plot title due to delayed evaluation.
  • Add autoplot.cps_mspct(), autoplot.raw_mspct() and autoplot.generic_spct() methods.
  • Add support for faceting to all autoplot() methods for collections of spectra.
  • Revise all autoplot() methods for collections of spectra adding support for sum, prod, var, sd, and se as summaries.
  • Update decoration() to track changes in ‘ggrepel’ (\>= 0.9.1).
  • Update decoration() to use position_nudge() and position_nudge_repel() to displace labels instead of “off-range” justification.
  • Improve handling of multiple spectra in long form by ggplot() methods and by autotitle().
  • Remove direct dependency on ‘dplyr’.
  • Add to the documentation of all autoplot() methods an explanation of how to modify the default plot annotations and tittles using arguments passed to parameter annotations. Also add *see also* links to related help pages.

  • Although this update should not break any code, the y-axis
    labels in plots returned by autoplot() methods have changed, in most cases only cosmetically to shorten them. In a few cases more significant changes correct problems.
  • Although this update should not break any code, the labels for
    peaks and valleys can be at a slightly different position than with
    earlier versions.
  • Although this update does not break any code, plots of collections of object spectra with normalization, will differ from earlier ones as member spectra are now normalized individually (this corrects an earlier bug!).

NOTE: The updated package is on its way to CRAN.

Please raise issues concerning bugs or enhancements to this package through Bitbucket at

Plans for upcoming versions of the suite

I just want to share what is in my “to do” list and what I wish someone else could contribute to the R for photobiology suite of packages either as part of the suite or as independent extensions. In addition to the enhancements listed below, I hope at some point to be able to submit the packages in the suite to R Open Science to be peer reviewed.

Continue reading