labels for formulas without intercepts do not show dependent variable

Create issue
Issue #38 resolved
Former user created an issue

For my formula without a y-intercept, y ~ x + 0, labels are being output as y = 3.25 instead of y = 3.25 x. It does not matter if I specify anything for eq.x.rhs. Am I doing something incorrectly?

rm(list=ls())
library(dplyr)
library(ggplot2)
library(ggpmisc)
set.seed(1234)

x <- 1:100
scale <- 3.25
y <- scale * x + rnorm(length(x), mean = 0, sd = 5)
formula <- y ~ x + 0

data.frame(x, y) %>%
  ggplot(aes(x, y)) +
  geom_point() +
  geom_smooth(method = 'lm', formula = formula) +
  ggpmisc::stat_poly_eq(aes(label = ..eq.label..), 
                        formula = formula, parse = TRUE) -> p1

Comments (2)

  1. Chris Nolte

    I had missed that the help for stat_poly_eq does say to use “-1” or “- 1” to specify no intercept, rather than “+ 0”.

    formula <- y ~ x - 1
    

    produces an appropriate label.

    Thanks, and feel free to close this issue!

  2. Log in to comment