Do you know how I would put in the R squared value rather than the
correlation by any chance?

Cheers


On Fri, Apr 25, 2014 at 12:56 PM, Shane Carey <careys...@gmail.com> wrote:

> Hey Frede,
>
> I found the answer,
>
> thanks for your help.
>
> Shane
>
>
> On Fri, Apr 25, 2014 at 12:42 PM, Shane Carey <careys...@gmail.com> wrote:
>
>> I just plotted one variable against the other, added a trend line and got
>> my R squared value. I presumed the absolute correlation from pairs() would
>> be the same?
>>
>>
>> On Fri, Apr 25, 2014 at 12:24 PM, Frede Aakmann Tøgersen <
>> fr...@vestas.com> wrote:
>>
>>> No it is difficult to say when I don’t know what you did in Excel and
>>> Sigma Plot. The latter I don’t know and do not use it my self.
>>>
>>>
>>>
>>> Yours sincerely / Med venlig hilsen
>>>
>>>
>>> *Frede Aakmann Tøgersen*
>>> Specialist, M.Sc., Ph.D.
>>> Plant Performance & Modeling
>>>
>>> *Technology & Service Solutions*
>>> T +45 9730 5135
>>> M +45 2547 6050
>>> fr...@vestas.com
>>> http://www.vestas.com
>>>
>>> Company reg. name: Vestas Wind Systems A/S
>>> This e-mail is subject to our e-mail disclaimer statement.
>>> Please refer to www.vestas.com/legal/notice
>>> If you have received this e-mail in error please contact the sender.
>>>
>>>
>>>
>>> *From:* Shane Carey [mailto:careys...@gmail.com]
>>> *Sent:* 25. april 2014 13:14
>>> *To:* Frede Aakmann Tøgersen
>>> *Cc:* r-help@r-project.org
>>> *Subject:* Re: [R] Linear line on pairs plot
>>>
>>>
>>>
>>> Great, thanks Frede,
>>>
>>>
>>>
>>> This works perfectly. Ive tested these correlations with ones in sigma
>>> plot and excel and for some reason the r squared value is different. Any
>>> idea why this is? Thanks again for your help.
>>>
>>>
>>>
>>> Cheers
>>>
>>>
>>>
>>> On Fri, Apr 25, 2014 at 11:57 AM, Frede Aakmann Tøgersen <
>>> fr...@vestas.com> wrote:
>>>
>>> Hi
>>>
>>> Have a look on how panel.smooth is defined:
>>>
>>> panel.smooth
>>> function (x, y, col = par("col"), bg = NA, pch = par("pch"),
>>>     cex = 1, col.smooth = "red", span = 2/3, iter = 3, ...)
>>> {
>>>     points(x, y, pch = pch, col = col, bg = bg, cex = cex)
>>>     ok <- is.finite(x) & is.finite(y)
>>>     if (any(ok))
>>>         lines(stats::lowess(x[ok], y[ok], f = span, iter = iter),
>>>             col = col.smooth, ...)
>>> }
>>> <bytecode: 0x000000000bfb2ce0>
>>> <environment: namespace:graphics>
>>>
>>>
>>> And change that to something like this:
>>>
>>>
>>> panel.regression <- function (x, y, col = par("col"), bg = NA, pch =
>>> par("pch"),
>>>     cex = 1, col.regres = "red", ...)
>>> {
>>>     points(x, y, pch = pch, col = col, bg = bg, cex = cex)
>>>     ok <- is.finite(x) & is.finite(y)
>>>     if (any(ok))
>>>         abline(stats::lm(y[ok] ~ x[ok]), col = col.regres, ...)
>>> }
>>>
>>>
>>> Substitute panel.smooth with panel.regression in your pairs.panel()
>>> function and you have it.
>>>
>>>
>>>
>>> Yours sincerely / Med venlig hilsen
>>>
>>>
>>> Frede Aakmann Tøgersen
>>> Specialist, M.Sc., Ph.D.
>>> Plant Performance & Modeling
>>>
>>> Technology & Service Solutions
>>> T +45 9730 5135
>>> M +45 2547 6050
>>> fr...@vestas.com
>>> http://www.vestas.com
>>>
>>> Company reg. name: Vestas Wind Systems A/S
>>> This e-mail is subject to our e-mail disclaimer statement.
>>> Please refer to www.vestas.com/legal/notice
>>> If you have received this e-mail in error please contact the sender.
>>>
>>>
>>> > -----Original Message-----
>>> > From: r-help-boun...@r-project.org [mailto:
>>> r-help-boun...@r-project.org]
>>> > On Behalf Of Shane Carey
>>> > Sent: 25. april 2014 12:26
>>> > To: r-help@r-project.org
>>> > Subject: [R] Linear line on pairs plot
>>> >
>>> > Hi,
>>> >
>>> > Im trying to plot a linear line on the scatter plot using the pairs()
>>> > function. At the moment the line is non linear. However, I want a
>>> linear
>>> > line and the associated R value.
>>> >
>>> > Here is my current code:
>>> >
>>> > panel.cor.scale <- function(x, y, digits=2, prefix="", cex.cor)
>>> > {
>>> >   usr <- par("usr"); on.exit(par(usr))
>>> >   par(usr = c(0, 1, 0, 1))
>>> >   r = (cor(x, y,use="pairwise"))
>>> >   txt <- format(c(r, 0.123456789), digits=digits)[1]
>>> >   txt <- paste(prefix, txt, sep="")
>>> >   if(missing(cex.cor)) cex <- 0.8/strwidth(txt)
>>> >   text(0.5, 0.5, txt, cex = cex * abs(r))
>>> > }
>>> >
>>> >
>>> > panel.cor <- function(x, y, digits=2, prefix="", cex.cor)
>>> > {
>>> >   usr <- par("usr"); on.exit(par(usr))
>>> >   par(usr = c(0, 1, 0, 1))
>>> >   r = (cor(x, y,use="pairwise"))
>>> >   txt <- format(c(r, 0.123456789), digits=digits)[1]
>>> >   txt <- paste(prefix, txt, sep="")
>>> >   if(missing(cex.cor)) cex <- 0.8/strwidth(txt)
>>> >   text(0.5, 0.5, txt, cex = cex )
>>> > }
>>> >
>>> >
>>> > panel.hist <- function(x, ...)
>>> > {
>>> >   usr <- par("usr"); on.exit(par(usr))
>>> >   par(usr = c(usr[1:2], 0, 1.5) )
>>> >   h <- hist(x, plot = FALSE)
>>> >   breaks <- h$breaks; nB <- length(breaks)
>>> >   y <- h$counts; y <- y/max(y)
>>> >   rect(breaks[-nB], 0, breaks[-1], y, col="cyan", ...)
>>> > }
>>> >
>>> >
>>> > pairs.panels <- function (x,y,smooth=TRUE,scale=FALSE)
>>> > {if (smooth ){
>>> >   if (scale) {
>>> >
>>> >
>>> pairs(x,diag.panel=panel.hist,upper.panel=panel.cor.scale,lower.panel=pane
>>> > l.smooth)
>>> >   }
>>> >   else
>>> > {pairs(x,diag.panel=panel.hist,upper.panel=panel.cor,lower.panel=
>>> panel.sm
>>> > ooth)
>>> >   } #else
>>> > {pairs(x,diag.panel=panel.hist,upper.panel=panel.cor,lower.panel=
>>> panel.sm
>>> > ooth)
>>> > }
>>> >  else #smooth is not true
>>> >  { if (scale)
>>> {pairs(x,diag.panel=panel.hist,upper.panel=panel.cor.scale)
>>> >  } else {pairs(x,diag.panel=panel.hist,upper.panel=panel.cor) }
>>> >  } #end of else (smooth)
>>> > } #end of function
>>> >
>>> > pairs.panels(iris[1:4])
>>> >
>>> > Thanks
>>> >
>>> > --
>>> > Shane
>>> >
>>>
>>> >       [[alternative HTML version deleted]]
>>> >
>>> > ______________________________________________
>>> > R-help@r-project.org mailing list
>>> > https://stat.ethz.ch/mailman/listinfo/r-help
>>> > PLEASE do read the posting guide http://www.R-project.org/posting-
>>> > guide.html
>>> > and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>>
>>>
>>>
>>> --
>>> Shane
>>>
>>
>>
>>
>> --
>> Shane
>>
>
>
>
> --
> Shane
>



-- 
Shane

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to