R Calculation Error Creating Ggplot2 Stat Extension Stack Overflow

R Calculation Error Creating Ggplot2 Stat Extension Stack Overflow