# [R] plots with symbols proportional to number of repeats

Ben Bolker ben at zoo.ufl.edu
Sun Sep 9 15:25:01 CEST 2001

```  Some of my students were interested in a plot where the sizes of the
symbols were proportional to the number of repeats in the data (I have
them plotting discrete data, so there are often overlaps).  Here's the
solution I came up with, which seems clever (to me) but not necessarily
the best way.  Can anyone suggest improvements?

sizeplot <- function(x,y,maxsize=0.2,
xlab=deparse(substitute(x)),
ylab=deparse(substitute(y)),
...) {
pair <- function(x,y) {
paste(x,y,sep="/")
}
unpair <- function(x) {
t(sapply(strsplit(x,"/"),as.numeric))
}
f <- factor(pair(x,y))
n <- table(f)
newpts <- unpair(levels(f))
symbols(newpts[,1],newpts[,2],circles=n,inches=maxsize,
xlab=xlab,ylab=ylab,...)
}

x <- c(0.1,0.1,0.1,0.1,0.1,0.2,0.2,0.2,0.2,0.3,0.3)
y <- c( 1,  1,  1,  1,  2,  2,  2,  3,  3,  4,  5 )

plot(x,y)

sizeplot(x,y)

--
318 Carr Hall                                bolker at zoo.ufl.edu
Zoology Department, University of Florida    http://www.zoo.ufl.edu/bolker
Box 118525                                   (ph)  352-392-5697
Gainesville, FL 32611-8525                   (fax) 352-392-3704

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```