Adding a regression equation to a scattergram

35 views
Skip to first unread message

pmay...@gmail.com

unread,
Nov 20, 2015, 5:40:39 AM11/20/15
to Deducer
Hi,
     I've built a scattergram template which does most of what I desire (labeling data points in particular).  The only thing I cannot achieve is adding a regression equation and R2 value to the plot.  I have a numer of ways that it can be done directly in R, but I am unable to figure out how to make any of them work in Deducer.  My attempts to use the Statistics>Function primitive end in tears. (Using data = " ", for example gets converted to something like data = \"\" which caused the whole thing to fall over.).  If, for example, I want to use Susane Johnston's approach, which puts the regression equation data in the title, can it be done in Deducer?

ggplotRegression <- function (fit) {
require(ggplot2)
ggplot(fit$model, aes_string(x = names(fit$model)[2], y = names(fit$model)[1])) +
  geom_point() +
  stat_smooth(method = "lm", col = "red") +
  labs(title = paste("Adj R2 = ",signif(summary(fit)$adj.r.squared, 5),
                     "Intercept =",signif(fit$coef[[1]],5 ),
                     " Slope =",signif(fit$coef[[2]], 5),
                     " P =",signif(summary(fit)$coef[2,4], 5))

fit1 <- lm(Sepal.Length ~ Petal.Width, data = iris)
ggplotRegression(fit1)

thank you,

Peter Mayer
Reply all
Reply to author
Forward
0 new messages