All Projects → wilkox → gglmannotate

wilkox / gglmannotate

Licence: other
📈Annotate a ggplot with a description of a linear model

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to gglmannotate

TDAstats
R pipeline for computing persistent homology in topological data analysis. See https://doi.org/10.21105/joss.00860 for more details.
Stars: ✭ 26 (+8.33%)
Mutual labels:  ggplot2
rust-lp-modeler
Lp modeler written in Rust
Stars: ✭ 75 (+212.5%)
Mutual labels:  linear-models
cusumcharter
Easier CUSUM control charts. Returns simple CUSUM statistics, CUSUMs with control limit calculations, and function to generate faceted CUSUM Control Charts
Stars: ✭ 17 (-29.17%)
Mutual labels:  ggplot2
R4Econ
R Code Examples Multi-dimensional/Panel Data
Stars: ✭ 16 (-33.33%)
Mutual labels:  ggplot2
basemapR
Contains functions to add base maps to ggplot2 maps
Stars: ✭ 14 (-41.67%)
Mutual labels:  ggplot2
platetools
An R package for plotting microtitre plates
Stars: ✭ 45 (+87.5%)
Mutual labels:  ggplot2
imprint
Create Customized 'ggplot2' and 'R Markdown' Themes for Your Organization
Stars: ✭ 24 (+0%)
Mutual labels:  ggplot2
scclusteval
Single Cell Cluster Evaluation
Stars: ✭ 57 (+137.5%)
Mutual labels:  ggplot2
Stata-schemes
Here you will find various ready-to-use Stata schemes.
Stars: ✭ 85 (+254.17%)
Mutual labels:  ggplot2
dataviz
Course materials for Kieran Healy's rstudio::conf 2020 data visualization workshop
Stars: ✭ 75 (+212.5%)
Mutual labels:  ggplot2
rockthemes
R colour palettes based on classic rock album covers.
Stars: ✭ 30 (+25%)
Mutual labels:  ggplot2
ggtrack
restlessdata.com.au/ggtrack
Stars: ✭ 39 (+62.5%)
Mutual labels:  ggplot2
ggfx
Filters and Shaders for 'ggplot2'
Stars: ✭ 150 (+525%)
Mutual labels:  ggplot2
mapr
Map species occurrence data
Stars: ✭ 34 (+41.67%)
Mutual labels:  ggplot2
figpatch
Easily Arrange Images with Patchwork Alongside ggplot2 Figures.
Stars: ✭ 46 (+91.67%)
Mutual labels:  ggplot2
ggdogs
The geom you always wished for adding dogs to ggplot2
Stars: ✭ 28 (+16.67%)
Mutual labels:  ggplot2
ggquiver
R package for quiver plots in 'ggplot2'
Stars: ✭ 38 (+58.33%)
Mutual labels:  ggplot2
BuenColors
R package of colors for the Buenrostro Lab
Stars: ✭ 53 (+120.83%)
Mutual labels:  ggplot2
ggbash
A simpler ggplot2 syntax, saving half of your typing.
Stars: ✭ 79 (+229.17%)
Mutual labels:  ggplot2
MSG-Book
📖 现代统计图形(已由人民邮电出版社出版) Modern Statistical Graphics
Stars: ✭ 95 (+295.83%)
Mutual labels:  ggplot2

lifecycle

gglmannotate annotates a ggplot2 with a description of a linear model.

Installation

Install the development version from GitHub:

devtools::install_github("wilkox/gglmannotate")

How to use

To add a description of a linear model to a scatter plot built with ggplot2, just add geom_lmannotate().

library(ggplot2)
library(gglmannotate)

ggplot(mpg, aes(x = displ, y = hwy)) +
  geom_point() +
  geom_smooth(method = "lm") +
  geom_lmannotate()

Grouping, for example by adding a colour aesthetic, is automatically handled.

ggplot(mpg, aes(x = displ, y = hwy, colour = class)) +
  geom_point() +
  geom_smooth(method = "lm") +
  geom_lmannotate()

Faceting is also supported.

ggplot(mpg, aes(x = displ, y = hwy)) +
  geom_point() +
  geom_smooth(method = "lm") +
  geom_lmannotate() +
  facet_wrap(~ class)

Customising the annotation text

The annotation can be changed from the default by setting the glue_exp argument to geom_lmannotate(), which will be parsed with the glue() function from the glue package. This allows interpolation of R variables and expressions. The linear model object (the output of lm()) is available inside the glue expression as the variable model. For example:

ggplot(mpg, aes(x = displ, y = hwy, colour = class)) +
  geom_point() +
  geom_smooth(method = "lm") +
  geom_lmannotate(glue_exp = "Max residual: {signif(max(model$residuals), 2)}")

Customising the annotation placement

To change the region of the plot area in which annotations will be drawn, use the region argument to geom_lmannotate(). It takes a named numeric vector with elements ‘xmin’, ‘xmax’, ‘ymin’ and ‘ymax’, all scaled between 0 and 1, to define the region.

The vertical and horizontal aliment of the text within the region can be set with place. It accepts the following values: “right”, “bottomright”, “bottom”, “bottomleft”, “left”, “topleft”, “top”, and “centre|center|middle”.

ggplot(mpg, aes(x = hwy, y = cty, colour = class)) +
  geom_point() +
  geom_smooth(method = "lm") +
  geom_lmannotate(
    region = c(xmin = 0, xmax = 0.75, ymin = 0.75, ymax = 1),
    place = "topleft"
  )

The annotation text layout can be further tweaked with the min.size, grow and reflow options. See the ggfittext package for full details on these options.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].