Please help me with scatterplot matrix coding.

panel.cor <- function(x, y){usr <- par("usr"); on.exit(par(usr))par(usr = c(0, 1, 0, 1)) r <- round(cor(x, y), digits=2)txt <- paste0("R = ", r)cex.cor <- 0.8/strwidth(txt)text(0.5, 0.5, txt, cex = cex.cor * r)}

Ive put this code in to plot the correlation values to a scatterplot matrix and it keeps coming up with this ERROR. Can you see any errors in my code???

Error: unexpected symbol in "panelcor <- function(x, y){usr <- par("usr"); on.exit(par(usr))par"

Welcome to the community!

The error in your code is the absence of ;'s at the end of statements. If you write a code in a script (or in console) where each statementis in it's own line, ; is not required. But if you write them in same line, you'll have to add them.

Try this: panel.cor <- function(x, y){usr <- par("usr"); on.exit(par(usr));par(usr = c(0, 1, 0, 1)); r <- round(cor(x, y), digits=2);txt <- paste0("R = ", r);cex.cor <- 0.8/strwidth(txt);text(0.5, 0.5, txt, cex = cex.cor * r)}.

Hope this helps.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.