
assigned issue to
 marked as critical
This post was copied over from the original post on Github, with a slightly modified title.
The problem
Settings in coef.digits
and rr.digits
are overridden to trim trailing zeros in the formatted coefficients and Rsquare, even if the zeros are part of the significant figures.
A reproducible example (R 3.5.2 and ggpmisc 0.3.0)
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)
Comments (6)

repo owner 
repo owner Revised code to generate the correct "expression text" for parsing, but trailing zeros are still being dropped later.

repo owner See https://stackoverflow.com/questions/15397789/keepingtrailingzeroeswithplotmath. This is how R's parse() behaves. The code needs to be reimplemented passing the numbers as character strings within the expression. We need to use an expression for the superscripts used for powers of x. The code as revised earlier today should produce the correct output with labels encoded as LaTeX.

repo owner  marked as major

repo owner The default of `coef.digits = 3', avoids the problem in the example above without solving it in general. Using 2 significant digits is too little for coefficient estimates. Now a warning is issued when fewer digits are used.

repo owner  changed status to on hold
The default of `coef.digits = 3', avoids the problem in the example above without solving it in general. Using 2 significant digits is too little for coefficient estimates. Now a warning is issued when fewer digits are used. This is a temporary fix, but should help in most cases.
 Log in to comment
Yes, the 1 with or without trailing zeros should be shown always for a fitted equation as it will never be exactly 1.