ggpmisc 0.5.0

R Package Update
ggpmisc pkg

Pedro J. Aphalo



Version 0.5.0 (previously announced as 0.4.8) brings enhancements to the annotations based on model fits. The most significant change for all users is the new convenience function use_label() that greatly simplifies the assembly of labels from components and their mapping to aesthetics. We examplify its use and some of the other new features. It also contains two changes that are not backwards compatible and that can in isolated cases break existing code (hence the version-number change into 0.5.0).

In the first plot we add an estimate of the correlation coeficient R, and the corresponding t-value and P-value.

ggplot(subset(mpg, cyl != 5), aes(displ, hwy, colour = factor(cyl))) +
  geom_point() +
  stat_correlation(use_label(c("R", "t", "P")),
                   label.x = "right") +

The displacement volume of car engines is known without error and it can the thought as a possible explanation for the petrol use per distance (MPG or miles per gallon) for hiway driving. We fit a linear regression, and annotate the plot with the fitted linear model equations, the F-values and P-values.

ggplot(subset(mpg, cyl != 5), aes(displ, hwy, colour = factor(cyl))) +
  geom_point() +
  stat_poly_line() +
  stat_poly_eq(use_label(c("eq", "F", "P")),
                   label.x = "right") +

In the case of the petrol use (MPG) in city traffic compared to highway travel the two variables can be expected to be subject to similar error variation and there is no directional cause-effect relationship between them. So, in this case OLS linear regression is not a suitable approach. We use major axis regression instead, and we add to the label, θ, the angle in degrees between the two lines that could have been fitted by linear regression using x or y as the explanaroty variable.

ggplot(subset(mpg, cyl != 5), aes(cty, hwy)) +
  geom_point(alpha = 0.2) +
  stat_ma_line() +
  stat_ma_eq(use_label(c("eq", "theta", "R2", "P"))) +

Changes compared to version 0.4.7, 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.5.0 has been submitted to CRAN.

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