# ggpmisc v0.3.0

Monthly downloads

## Miscellaneous Extensions to 'ggplot2'

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.

## Readme

# ggpmisc

Package ‘**ggpmisc**’ (Miscellaneous Extensions to ‘ggplot2’) is a set
of extensions to R package ‘ggplot2’ (>= 3.0.0) with emphasis on
annotations and highlighting related to fitted models and data
summaries. To complement these, the widely useful `geom_table()`

and
`stat_fmt_tb()`

are defined as well as `ggplot`

constructors for time
series objects. The provided `ggplot.ts()`

and `ggplot.xts()`

use
`try_tibble()`

which is also exported and accepts objects of additional
classes as input.

Statistics useful for highlighting and/or annotating individual data
points in regions of plot panels with high/low densities of
observations. These stats are designed to work well together with
`geom_text_repel()`

and `geom_label_repel()`

from package ‘ggrepel’.

**Note:** Functions for the manipulation of layers in ggplot objects and
statistics and geometries that echo their data input to the R console,
earlier included in this package are now in package ‘gginnards’.

## Examples

```
library(ggplot2)
library(ggpmisc)
```

In the first example we plot a time series using the specialized version
of `ggplot()`

that converts the time series into a tibble and maps the
`x`

and `y`

aesthetics automatically. We also highlight and label the
peaks using `stat_peaks`

.

```
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") +
expand_limits(y = 8000)
```

In the second example we add the equation for a fitted polynomial plus
the adjusted coefficient of determination to a plot showing the
observations plus the fitted curve and confidence band. We use
`stat_poly_eq()`

.

```
formula <- y ~ x + I(x^2)
ggplot(cars, aes(speed, dist)) +
geom_point() +
geom_smooth(method = "lm", formula = formula) +
stat_poly_eq(aes(label = paste(..eq.label.., ..adj.rr.label.., sep = "~~~~")),
formula = formula, parse = TRUE)
```

The same figure as in the second example but this time annotated with
the ANOVA table for the model fit. We use `stat_fit_tb()`

which can be
used to add ANOVA or summary tables.

```
formula <- y ~ x + I(x^2)
ggplot(cars, aes(speed, dist)) +
geom_point() +
geom_smooth(method = "lm", formula = formula) +
stat_fit_tb(method = "lm",
method.args = list(formula = formula),
tb.type = "fit.anova",
tb.vars = c(Effect = "term",
"df",
"M.S." = "meansq",
"italic(F)" = "statistic",
"italic(P)" = "p.value"),
label.y.npc = "top", label.x.npc = "left",
parse = TRUE)
#> Warning in seq.default(along = x): partial argument match of 'along' to
#> 'along.with'
```

## Installation

Installation of the most recent stable version from CRAN:

```
install.packages("ggspectra")
```

Installation of the current unstable version from Bitbucket:

```
# install.packages("devtools")
devtools::install_bitbucket("aphalo/ggspectra")
```

## Documentation

HTML documentation is available at
(http://docs.r4photobiology.info/ggpmisc/), including a *User Guide*.

News on updates to the different packages of the ‘r4photobiology’ suite are regularly posted at (https://www.r4photobiology.info/).

## Contributing

Please report bugs and request new features at (https://bitbucket.org/aphalo/ggpmisc/issues). Pull requests are welcome at (https://bitbucket.org/aphalo/ggpmisc).

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

## Citation

If you use this package to produce scientific or commercial publications, please cite according to:

```
citation("ggpmisc")
#>
#> To cite ggpmisc in publications, please use:
#>
#> Pedro J. Aphalo. (2016) Learn R ...as you learnt your mother
#> tongue. Leanpub, Helsinki.
#>
#> A BibTeX entry for LaTeX users is
#>
#> @Book{,
#> author = {Pedro J. Aphalo},
#> title = {Learn R ...as you learnt your mother tongue},
#> publisher = {Leanpub},
#> year = {2016},
#> url = {https://leanpub.com/learnr},
#> }
```

## License

© 2016-2018 Pedro J. Aphalo (pedro.aphalo@helsinki.fi). Released under the GPL, version 2 or greater. This software carries no warranty of any kind.

## Functions in ggpmisc

Name | Description | |

stat_fit_tb | Model-fit summary or ANOVA | |

try_data_frame | Convert an R object into a tibble | |

ggplot | Create a new ggplot plot from time series data | |

stat_fit_augment | Augment data with fitted values and statistics | |

stat_dens2d_labels | Reset labels of observations in high density regions | |

stat_dens2d_filter | Filter observations by local density | |

geom_table | Tables | |

find_peaks | Find local maxima or global maximum (peaks) | |

gtb_draw_panel_fun | Stat* Objects | |

stat_quadrat_counts | Renamed to stat_quadrant_counts | |

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

Moved | Moved to package 'gginnards' | |

stat_peaks | Local maxima (peaks) or minima (valleys) | |

stat_quadrant_counts | Number of observations in quadrants | |

stat_fit_glance | One row summary data frame for a fitted model | |

stat_fit_deviations | Residuals from model fit as segments | |

stat_fit_tidy | One row data frame with fitted parameter estimates | |

stat_poly_eq | Equation, p-value, R^2, AIC or BIC of fitted polynomial | |

stat_fit_residuals | Residuals from a model fit | |

stat_fmt_tb | Select and slice a tibble nested in data | |

No Results! |

## Vignettes of ggpmisc

Name | ||

user-guide.Rmd | ||

No Results! |

## Last month downloads

## Details

Type | Package |

Date | 2018-07-16 |

License | GPL (>= 2) |

LazyData | TRUE |

LazyLoad | TRUE |

ByteCompile | TRUE |

URL | https://www.r4photobiology.info, https://bitbucket.org/aphalo/ggpmisc |

BugReports | https://bitbucket.org/aphalo/ggpmisc/issues |

RoxygenNote | 6.0.1 |

VignetteBuilder | knitr |

NeedsCompilation | no |

Packaged | 2018-07-16 11:12:08 UTC; aphalo |

Repository | CRAN |

Date/Publication | 2018-07-16 13:40:03 UTC |

imports | broom (>= 0.4.4) , dplyr (>= 0.7.6) , grid , gridExtra (>= 2.3) , lubridate (>= 1.7.4) , magrittr (>= 1.5) , MASS (>= 7.3-50) , plyr (>= 1.8.4) , polynom (>= 1.3-9) , rlang (>= 0.2.1) , splus2R (>= 1.2-2) , tibble (>= 1.4.2) , xts (>= 0.10-2) , zoo (>= 1.8-1) |

depends | ggplot2 (>= 3.0.0) , R (>= 3.3.0) |

suggests | ggrepel (>= 0.8.0) , knitr (>= 1.20) , nlme (>= 3.1-137) , rmarkdown (>= 1.10) |

Contributors | Kamil Slowikowski |

#### Include our badge in your README

```
[![Rdoc](http://www.rdocumentation.org/badges/version/ggpmisc)](http://www.rdocumentation.org/packages/ggpmisc)
```