diff --git a/r/graph-functions.r b/r/graph-functions.r index 6e5bd8b..f90aa3b 100644 --- a/r/graph-functions.r +++ b/r/graph-functions.r @@ -123,28 +123,15 @@ # function for producing a scatter plot #pointlabels are labels to be rendered beside each point on the plot -scatter <- function(pointlabels=NULL, x, y, xlab, ylab, maxx=100, maxy=100, stats=TRUE, fit=TRUE, ...) { - - # replace nas with 0 - x[is.na(x)] <- 0 - y[is.na(y)] <- 0 - - # calculate correlation - r <- cor(x, y) - - r2 = round(r ** 2,2) - - # concat r string with rounded value - r <- substitute('r'^2*' = '*r2, list(r2 = r2)) - +scatter <- function(pointlabels=NULL, x, y, xlab, ylab, maxx=100, maxy=100, fit=FALSE, ...) { # plot x vs y as solid points (thats what the pch=19 means) points plot(x, y, xlim=c(0,maxx), ylim=c(0,maxy), col="light blue", pch=19, xlab=xlab, ylab=ylab, xaxt='n',yaxt='n', ...) # plot some grid lines - abline(h=seq(0, maxy, 10), col="grey", lty="solid", lwd=0.5) - abline(v=seq(0, maxx, 10), col="grey", lty="solid", lwd=0.5) - abline(a=0, b=1, col="grey") + abline(h=seq(0, maxy, 10), col="light grey", lty="solid", lwd=0.5) + abline(v=seq(0, maxx, 10), col="light grey", lty="solid", lwd=0.5) +# abline(a=0, b=1, col="light grey", lwd=0.5) # plot the graph points(x, y, xlim=c(0,maxx), ylim=c(0,maxy), col="light blue", pch=19, xlab=xlab, ylab=ylab, ...) @@ -159,6 +146,8 @@ par(op) + mtext("Scatter Plot", side=3, line=0.25) + # replot the points with darker outline to create a border around the points points(x,y, col="dark blue") @@ -171,11 +160,6 @@ text(xlabelpos,y,pointlabels, cex=0.5) } - if(stats) { - # render the r text in the bottom right - text(maxx-maxx*0.1,2,r) - } - # change plot color op <- par(col="red") @@ -183,15 +167,16 @@ co$x <- x co$y <- y - valid <- co$x > 10 & co$y>10 + valid <- is.na(co$x) | is.na(co$y) + valid <- !valid co$x <- co$x[valid] co$y <- co$y[valid] - + if(fit) { # render a lowess regression lines(lowess(co)) - + #abline(reggie) } # restore original plot params @@ -257,8 +242,7 @@ abline(h=seq(0,100, by=5), col="grey", lty="solid", lwd=0.5) axis(2, at=seq(0,100, by=10), las=1) -# axis(1, labels=levels(labs), at=seq(1, length(levels(labs))), font=2, ...) - axis(1, labels=levels(data$Assessment), at=seq(1, length(levels(data$Assessment))), font=2, ...) + axis(1, labels=levels(labs), at=seq(1, length(levels(labs))), font=2, ...) if(!is.null(extras)) { for(i in 1:length(extras)) {