# Contributed GNU-R Code

Use the comments box here to contribute GNU-R functions/code that you may have prepared. The idea is to use this space to archive interesting little snippets of codes that may be useful to others.

Please note that all “<” in your codes will have to be replaced by a “<” (without quotes) and all “> ” will have to be replaced by a “>”. This is to distinguish them from html/css tags.

Please provide your e-mail so that people interested in using your code could contact you if needed. Comments will be moderated only to prevent spam.

V.

## Chandan Mukherjee

Here is a function ‘scatterbox’ which plots y against x along with the boxplots of them and the lowess fit to the scatterplot.

scatterbox <- function (x, y, …)

{

def.par <- par(no.readonly = TRUE)

n <- length(x)

xbox <- boxplot(x, plot = FALSE)

ybox <- boxplot(y, plot = FALSE)

xrange <- c(min(x), max(x))

yrange <- c(min(y), max(y))

low<-lowess(x,y)

nf <- layout(matrix(c(2, 0, 1, 3), 2, 2, TRUE), c(6, 1),

c(1, 6), TRUE)

layout.show(nf)

par(mar = c(5, 5, 0, 0))

plot(x, y, xlim = xrange, ylim = yrange, …)

lines(low$x,low$y)

par(mar = c(0, 5, 1, 1))

bxp(xbox, outline=FALSE, axes=FALSE, horiz=TRUE)

par(mar = c(5, 0, 1, 1))

bxp(ybox, outline=FALSE, axes=FALSE)

par(def.par)

}

An example is

x<-sort(rnorm(100))

y<-sort(rt(100,3))

source(“~/scatterbox.R”)

scatterbox(x,y)

The output looks like this