ggpmisc 0.3.9

Package ‘ggpmisc’ focuses mainly on plot annotations. The new version fixes minor bugs and adds a major new feature: position functions for data aware nudging. These nudge functions were born out of an exchange of ideas with Kamil Slowikowski, the author and maintainer of the very popular package ‘ggrepel’. We are currently considering how to make them compatible with geom_text_repel() and geom_label_repel().

The package documentation web site at: https://docs.r4photobiology.info/ggpmisc/ now includes a changelog, so I am brief here.

Changes from version 0.3.8, the most recent CRAN release, are:

  • Update the documentation of geom_plot().
  • [Under development!] Link repositioned text to its original position with a segment or arrow: geom_linked_text(). Except for
    the drawing of segments or arrows this new geometry behaves as ggplot2::geom_text() . Note: Segments and arrows are drawn only
    if the position function used returns both the repositioned and original coordinates.
  • Add support for advanced nudging: position_nudge_centre() and position_nudge_line() compute the direction of nudging and return
    both the nudged and original positions.
  • Add support for simple nudging: position_nudge_to() nudges to new user-supplied position(s); position_nudge_keep() nudges to
    position(s) based on user-supplies position shift. These functions return both nudged and original position(s).

Example: Nudging text labels away from a curve.

library(ggpmisc)

set.seed(16532)
df <- data.frame(
  x = -10:10,
  y = (-10:10)^2 + rnorm(21, 0, 4),
  l = letters[1:21]
)

ggplot(df, aes(x, y, label = l)) +
  geom_point() +
  stat_smooth(method = "lm", formula = y ~ poly(x, 2, raw = TRUE)) +
  geom_text(aes(y = y, label = l),
            position = position_nudge_line(method = "lm",
                                           x = 0.4, 
                                           y = 4,
                                           formula = y ~ poly(x, 2, raw = TRUE),
                                           direction = "split"))
The resulting plot.
Nudging of text labels away from a curve.

Roadmap: A split of the ‘ggpmisc’ package into two packages, one including the extensions to the grammar of graphics and another one including the functions related to plot annotations based on model fitting and statistical summaries seems necessary as the package has grown to include several extensions to the grammar of graphics that are generally useful. We are also working on improved inter-operation between ‘ggpmisc’ and ‘ggrepel’.

Acknowlegement: I thank Kamil Slowikowski for his contributions of ideas and for his willingness to keep the development of our packages coordinated. This update was done in part to address questions raised and reports of bugs by users, which I thank. The tag [ggpmisc] is in use at stackoverflow for questions related to the use this package. Please raise issues concerning bugs or enhancements to this package through GitHub at https://github.com/aphalo/ggpmisc/issues. Pull requests are also welcome.

Documentation web site at http://docs.r4photobiology.info/ggpmisc/ includes all help pages, with output from all examples, and vignettes in HTML format. The online vignettes include the output of all code examples, while the vignettes as included in the package, contain the output of only a subset of the code examples so as to keep the documentation at a reasonable size for package distribution.

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

ggpmisc 0.3.8

[27 January] ‘ggpmisc’ 0.3.8-1 is on its way to CRAN. The only change is correcting a mistake in a vignette. This was caused by the code-breaking change now highlighted below.

Package ‘ggpmisc’ focuses mainly on plot annotations. The new version adds fixes bugs and adds some minor feature. There are more significant changes to the documentation.

The package documentation web site at: https://docs.r4photobiology.info/ggpmisc/ now includes a changelog, so I am brief here.

Changes from version 0.3.7 the most recent CRAN release, are:

  • Move of the Git repository from Bitbucket to GitHub.
  • Revise stat_fit_glance(), stat_fit_augment(), stat_fit_tidy() and stat_fit_tb() to add support for additional methods and make it possible to pass additional arguments. This is a code-breaking change in that packages ‘broom’ and/or ‘broom.mixed’ need to be loaded explicitly with library().
  • Fix bugs related to handling of Date values.

Acknowlegement: This update was done in part to address questions raised at stackoverflow. The tag [ggpmisc] is in use at stackoverflow for questions related to this package.

Documentation web site at http://docs.r4photobiology.info/ggpmisc/ includes all help pages, with output from all examples, and vignettes in HTML format.

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

Please raise issues concerning bugs or enhancements to this package through GitHub https://github.com/aphalo/ggpmisc/issues.

ggpmisc 0.3.7

Package ‘ggpmisc’ focuses mainly on plot annotations. The new version adds features that I hope will be found useful.

Package documentation web site at: https://docs.r4photobiology.info/ggpmisc/

Changes from version 0.3.6 the most recent CRAN release, are:

New

Filtering based on 1D density

Three new statistics stat_dens1d_filter(), stat_dens1d_filter_g() and stat_dens1d_labels() are 1D versions of the existing 2D functions which received a minor update.

  • Add stat_dens1d_filter(), stat_dens1d_filter_g() and stat_dens1d_labels(), to complement existing stat_dens2d_filter(), stat_dens2d_filter_g() and stat_dens2d_labels().
  • Update stat_dens2d_filter(), stat_dens2d_filter_g() and stat_dens2d_labels() adding formal parameters keep.sparse and invert.selection, as available in the new 1D versions.
  • Update stat_dens2d_labels() to accept not only character strings but also functions as argument to label.fill as the new stat_dens1d_labels() does.

Table insets and their formatting

Updates to statistics stat_fmt_tb() and stat_fit_tb() add flexibility.

  • Update stat_fit_tb() to support renaming of terms/parameter names in the table (Suggested by Big Old Dave and Z. Lin). In addition implement selection, reordering and renaming of columns and terms/parameters using positional indexes and pattern matching of truncated names in addition to whole names. Improve formatting of small P-values.
  • Update stat_fmt_tb() to support the same expanded syntax as stat_fit_tb().

Here is an example for an ANOVA table inset.

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",
              tb.vars = c(Term = "term", "df", "M.S." = "meansq",
                          "italic(F)" = "statistic",
                          "italic(p)" = "p.value"),
              tb.params = c("Group" = 1, "Error" = 2),
              table.theme = ttheme_gtbw(parse = TRUE)) +
  labs(x = "Group", y = "Dry weight of plants") +
  theme_classic()

 

Acknowlegement: This update was encouraged by recent questions at stackoverflow. The tag [ggpmisc] is in use at stackoverflow for questions related to this package.

Documentation web site at http://docs.r4photobiology.info/ggpmisc/ includes all help pages, with output from all examples, and vignettes in HTML format.

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

Please raise issues concerning bugs or enhancements to this package through Bitbucket https://github.com/aphalo/ggpmisc/issues.

ggpmisc 0.3.6

Package ‘ggpmisc’ focuses mainly on plot annotations. The new features added in this version required quite minor code changes but add features that I hope will be found useful.

Changes from version 0.3.5 the most recent CRAN release, are:

New

Annotations using NPC coordinates

NPC or native plot coordinates, are very useful for annotations. On the other hand, they are not of any use for plotting actual data. The geometries using this kind of position coordinates defined in ‘ggpmisc’ make it possible to have different annotations in the different panels when using facets. Traditional annotations in ‘ggplot2’ do not use the data, but instead take as arguments constant values for the aesthetics, and consequently add identical annotations to all panels. Annotations in ‘ggplot2’ use data coordinates. In many cases, the desired position of annotations is unrelated to the data, but instead related to the native coordinates of the plotting viewport. Using NPC coordinates for annotations allows consistent positioning, which is very important from the graphical design perspective.

Starting from version 0.3.6  ‘ggpmisc’ exports a modified definition of annotate() from ‘ggplot2’. The modification adds support of the position aesthetics npcx and npcy retaining all other functionality unaltered. As a consequence geometries "text_npc""label_npc""table_npc", "plot_npc", and "grob_npc" can now be used as the first argument to annotate(). In addition single ggplots, data frames and grobs as well as lists of such objects are accepted arguments to label.

library(ggpmisc)

# plot to be inset
p <- ggplot(mtcars, aes(factor(cyl), mpg, colour = factor(cyl))) +
  stat_boxplot() +
  labs(y = NULL) +
  theme_bw(9) + theme(legend.position = "none")

# main plot with p as an inset
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
  geom_point() +
  annotate("plot_npc", npcx = "left", npcy = "bottom", label = p) +
  expand_limits(y = 0, x = 0)

Tagging equations with group labels (experimental)

Starting from version 0.3.6  stat_poly_eq() supports use of grouping with equations and identifying them by using labels.  Previously use of  the color aesthetic was the only way of “linking” equations to plotted curves, which is frequently distracting or unavailable for printing. After some past failed attempts at implementing this, I recently realized that using a pseudo-aesthetic made implementation very easy and its use flexible and straightforward. The catch is that this relies on undocumented behavior of ‘ggplot2’ and will not necessarily work with future versions of ‘ggplot2’. Statistic stat_poly_eq() now copies grp.label from its input into its returned value. One can map any variable to the pseudo-aesthetic grp.label to achieve this. Values are passed to the output only if all values within the group are the same, otherwise grp.label is filled with NA. The signature of stat_poly_eq() remains unchanged.

library(ggpmisc)

my.formula <- y ~ x

ggplot(mtcars, aes(wt, mpg, 
                   linetype = factor(cyl), shape = factor(cyl),
                   grp.label = factor(cyl))) +
  geom_point() +
  stat_smooth(formula = my.formula, method = "lm", colour = "black") +
  stat_poly_eq(aes(label = stat(paste("bold(\"cyl\"~~", grp.label, 
                                      "*':')~~~", eq.label, sep = ""))), 
               formula = my.formula, label.x = "right", parse = TRUE) +
  theme_classic()

Marking and or labeling group centroids

The new stat_centroid() and stat_summary_xy(). stat_centroid() applies the same function to x and y and this function defaults to mean(). In the case of stat_summary_xy() the functions applied to x and y are passed as separate arguments, and they both default to simply copying their input.

Markdown

Starting from version 0.3.6, statistic stat_poly_eq() can optionally generate character strings encoded in markdown suitable for geom_richtext() from package ‘ggtext’.

Acknowlegement: This update was encouraged by recent questions at stackoverflow. The tag [ggpmisc] is in use at stackoverflow for questions related to this package.

Documentation web site at http://docs.r4photobiology.info/ggpmisc/ includes all help pages, with output from all examples, and vignettes in HTML format.

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

Please raise issues concerning bugs or enhancements to this package through Bitbucket https://bitbucket.org/aphalo/ggpmisc/issues.

Back to Top