0

I am trying to create a graph for my thesis data and am receiving the error message below. The graph runs, but the equations are not printed on it. I can't figure out what the issue is. There was a row with 'NA', but I removed it manually from the data.frame.

****Warning message: Computation failed in stat_poly_eq(): variable lengths differ (found for '(weights)')****

Any help will be greatly appreciated. The code for my graph that renders the error is below.

scatter.smooth(logspinbossht ~ logtestdia2)

df <- data.frame(logtestdia2, logspinbossht)

df6 <- df6[-c(574), ] ##remove NA

formula6 <- logspinbossht ~ logtestdia2
reg6 <- ggplot(df6, aes(x = logtestdia2, y = logspinbossht)) +
  geom_point() + 
  stat_smooth() + 
  stat_poly_eq(
    aes(label = paste(stat(eq.label), stat(adj.rr.label), sep = "~~~~")),
    formula = formula6, 
    parse=TRUE
  )

reg6 + 
  ggtitle("Spine Boss Length vs Test Diameter") + 
  xlab("Log Transformed Test Diameter (mm)") + 
  ylab("Log Transformed Spine Boss Length (mm)")
Gallarus
  • 476
  • 3
  • 9
Raven
  • 3
  • 2
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Feb 04 '20 at 20:22

1 Answers1

0

I suspect your issue may be the consequence of object confusion.

Your code implies that you have two vector objects (named logtestdia2 and logspinbossht) of a particular length. These are put into the data.frame object df6, and one row of df6 is removed.

Later you use the df6 data.frame for the ggplot() call, but also the formula that is based on the vector objects. These vectors are one-element longer than the df6. The mismatch in length causes the warning.

If I'm right, your code might work if you adjust the formula as follows:

library(ggplot2)
library(ggpmisc)

# fake vector data
logtestdia2 <- log(sample(1:100, 1000, replace = TRUE))
logspinbossht <- log(sample(1:10, 1000, replace = TRUE))

# fake data.frame
df6 <- data.frame(logtestdia2,logspinbossht)

# remove row
df6 = df6[-c(574), ] 

# use the vectors from the data.frame
formula6 = df6$logspinbossht ~ df6$logtestdia2

# plot
reg6 <- ggplot(df6, aes(x = logtestdia2, y = logspinbossht))+
  geom_point()+
  stat_smooth()+
  stat_poly_eq(aes(label=paste(stat(eq.label),stat(adj.rr.label),sep = "~~~~")),formula=formula6,parse=TRUE)+
  ggtitle("Spine Boss Length vs Test Diameter")+
  xlab("Log Transformed Test Diameter (mm)")+
  ylab("Log Transformed Spine Boss Length (mm)")

reg6
xilliam
  • 2,074
  • 2
  • 15
  • 27