cran / ggpmisc

:exclamation: This is a read-only mirror of the CRAN R package repository. ggpmisc — Miscellaneous Extensions to 'ggplot2'. Homepage: https://docs.r4photobiology.info/ggpmisc/, https://github.com/aphalo/ggpmisc Report bugs for this package: https://github.com/aphalo/ggpmisc/issues
15 stars 7 forks source link

stat_poly_eq() removes significant trailing zeros #1

Open e-clin opened 7 years ago

e-clin commented 7 years ago

The problem

Settings in coef.digits and rr.digits are overridden to trim trailing zeros in the formatted coefficients and R-square, even if the zeros are part of the significant figures.

A reproducible example

If coef.digits = 2, a slope of 1.04 should be shown as 1.0. Instead, 1.0 was simplified as 1 and subsequently not displayed. The resultant equation is misleading as the regression line is clearly unparallel with the 1:1 line as shown in the example code below:

library(tidyverse)
library(ggpmisc)

set.seed(2017)

tdf <- data.frame(
    x = 1:100,
    y = 1.04 * 1:100 + rnorm(100)
)

ggplot(aes(x = x, y = y), data = tdf) + 
    geom_point() + 
    geom_smooth(method = "lm") +
    stat_poly_eq(
        aes(label = paste(..eq.label.., ..rr.label.., sep = "*plain(\",\")~")),
        formula = y ~ x,
        coef.digits = 2,
        rr.digits = 3,
        parse = TRUE
    ) +
    geom_abline(slope = 1, intercept = 0, linetype = 2)
Rekyt commented 5 years ago

Hey @e-clin, it's great that you showed a bug. However, the development of ggpmisc happens mostly on bitbucket (https://bitbucket.org/aphalo/ggpmisc) so you should post the issue over there. This repository is only a clone made by the @cran-robot to have a duplicate of CRAN on GitHub.

e-clin commented 5 years ago

@Rekyt Thanks for your message. I have now duplicated this post on Bitbucket.