ggpmisc (version 0.3.0)

ggpmisc-package: ggpmisc: Miscellaneous Extensions to 'ggplot2'

Description

Extensions to 'ggplot2' respecting the grammar of graphics paradigm. Specialization of method ggplot(): accept and convert on the fly time series data. Geom: "table", adds tables to plots. Statistics: locate and tag peaks and valleys in 2D plots; count observations in different quadrants of a plot; select observations based on 2D density; label with the equation of a polynomial fitted with lm() or other types of models; labels with P-value, R^2 or adjusted R^2 or information criteria for fitted models; label with ANOVA table for fitted models; label with summary for fitted models. Model fit classes for which suitable methods are provided by package 'broom' are supported.

Arguments

Warning!

geom_null(), stat_debug_group(), stat_debug_panel(), geom_debug(), append_layers(), bottom_layer(), delete_layers(), extract_layers(), move_layers(), num_layesr(), shift_layers(), top_layer() and which_layers() have been moved from package 'ggpmisc' into their own seperate package 'gginnards-package.

Acknowledgements

We thank Kamil Slowikowski not only for contributing ideas and code examples to this package but also for adding new features to his package 'ggrepel' that allow new use cases for stat_dens2d_labels from this package.

Details

The new facilities for cleanly defining new stats and geoms added to 'ggplot2' in version 2.0.0 and the support for nested tibbles and new syntax for mapping computed values to aesthetics added to 'ggplot2' in version 3.0.0 are used in this package's code. This means that 'ggpmisc' (>= 0.3.0) requires version 3.0.0 or later of ggplot2 while 'ggpmisc' (< 0.3.0) requires version 2.0.0 or later of ggplot2.

Extensions provided:

  • Function for conversion of time series data into tibbles that can be plotted with ggplot.

  • ggplot() method for time series data.

  • Stats for locating and tagging "peaks" and "valleys" (local or global maxima and minima).

  • Stat for generating labels from a lm() model fit, including formatted equation. By default labels are expressions but tikz device is supported optionally with LaTeX formatted labels.

  • Stats for extracting information from a any model fit supported by package 'broom'.

  • Stats for filtering-out/filtering-in observations in regions of a panel or group where the density of observations is high.

  • Geom for annotating plots with tables.

The stats for peaks and valleys are coded so as to work correctly both with numeric and POSIXct variables mapped to the x aesthetic. Special handling was needed as text labels are generated from the data.

References

Package suite 'r4photobiology' web site at https://www.r4photobiology.info/ Package 'ggplot2' web site at http://ggplot2.org/ Package 'ggplot2' documentation at http://docs.ggplot2.org/ Package 'ggplot2' source code at https://github.com/hadley/ggplot2

See Also

Useful links:

Examples

Run this code
# NOT RUN {
library(ggplot2)

ggplot(lynx, as.numeric = FALSE) + geom_line() +
stat_peaks(colour = "red") +
  stat_peaks(geom = "text", colour = "red", angle = 66,
             hjust = -0.1, x.label.fmt = "%Y") +
  ylim(NA, 8000)

formula <- y ~ poly(x, 2, raw = TRUE)
ggplot(cars, aes(speed, dist)) +
  geom_point() +
  geom_smooth(method = "lm", formula = formula) +
  stat_poly_eq(aes(label = ..eq.label..), formula = formula,
               parse = TRUE)

formula <- y ~ x
ggplot(PlantGrowth, aes(group, weight)) +
  stat_summary(fun.data = "mean_se") +
  stat_fit_tb(method = "lm",
              method.args = list(formula = formula),
              tb.type = "fit.anova") +
  theme_classic()

# }

Run the code above in your browser using DataLab