[R] Error : unused arguments in pairs()

herwig bachmannherwig at hotmail.com
Tue Jan 6 16:13:57 CET 2009


Dear Sarah,

Thank you a lot,
It does exactly what I need.
By the way, I tried doing what Prof. Ripley suggested I just was not able to
get it right - I am pretty new to this after all.
Thank again,

Herwig


Sarah Goslee wrote:
> 
> You didn't do what Prof. Ripley suggested - adding a ... argument.
> Here's a crude version of what you want; I'm sure there's a more elegant
> solution for passing the needed data to the panel function.
> 
> panel.cor <- function(x, y, digits=2, prefix="", splitvar, col.cor, ...)
> 
> {
>    usr <- par("usr"); on.exit(par(usr))
>    par(usr = c(0, 1, 0, 1))
>    r <- abs(cor(x, y))
>    if(!missing(splitvar)) {
>       r <- c(r, abs(sapply(lapply(split(cbind.data.frame(x, y),
> splitvar), cor), function(x)x[1,2])))
>    }
>    txt <- format(c(r, 0.123456789), digits=digits)[1:4]
>    txt <- paste(prefix, txt, sep="")
>    if(missing(col.cor)) col.cor <- c("black", "red", "green3", "blue")
>    for(i in 1:length(txt)) {
>       text(0.5, (1/(length(txt)+1))*i, txt[i], col = col.cor[i])
>    }
>  }
> 
>  pairs(iris[1:4], main = "Anderson's Iris Data -- 3 species",
>      pch = 21, bg = c("red", "green3", "blue")[unclass(iris$Species)],
> lower.panel=panel.cor, splitvar=iris$Species)
> 
> 
> On Mon, Jan 5, 2009 at 5:32 PM, herwig <bachmannherwig at hotmail.com> wrote:
>>
>> Dear Prof. Ripley,
>>
>> thanks for your reply.
>> Unfortunately I still was not able to solve the problem.
>> I tried it with the Iris data and you can find the code below:
>>
>>>  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 <- abs(cor(x, y))
>>    txt <- format(c(r, 0.123456789), digits=digits)[1]
>>    txt <- paste(prefix, txt, sep="")
>>    if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt)
>>    text(0.5, 0.5, txt, cex = cex.cor * r)
>>  }
>>
>>  pairs(iris[1:4], main = "Anderson's Iris Data -- 3 species",
>>      pch = 21, bg = c("red", "green3", "blue")[unclass(iris$Species)],
>> lower.panel=panel.cor )
>>
>> What I would ideally like to have is that the upper panel shows the plot
>> with the iris$Species color coded and the lower panel showing the
>> correlation coefficients  for the total data in the plot, but also for
>> the
>> each iris$Species with the same color code as in the upper panels.
>> So the lower panel should therefore actually show 4 correlation
>> coefficients
>> in each panel (color coded); It does not need to be sized according to
>> the
>> value of the correlation coefficient as shown in the example above.
>> Any help with this would be appreciated a lot,
>>
>> Kind regards,
>>
>> Herwig
>>
>>
>>
> -- 
> Sarah Goslee
> http://www.functionaldiversity.org
> 
> ______________________________________________
> R-help at 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/Error-%3A-unused-arguments-in---pairs%28%29-tp21283398p21312270.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list