[R] dot diagram

Jinsong Zhao jszhao at mail.hzau.edu.cn
Sun Apr 9 08:07:29 CEST 2006


Hi,

I am wondering whether there is a function that could plot 
a dot diagram like the output of following code.

Thanks in advance!

Best wishes!

Jinsong


--------->my dirty code here<---------

mydata <- c(26,26,27,27,27,27,28,28,28,28,28,28,28,28,28,
	    28,28,28,28,29,29,29,29,29,29,29,29,29,29,29,
		30,30,30,30,30,30,30,30,31,31,31,31,32,33,33,
		33,34,34,35,43)

my.dot.plot <- function(x, ...) {
    x.table <- table(x)
    x.x <- as.numeric(names(x.table))
    x.y <- as.numeric(x.table)
    n <- length(x.x)
    x.final <- NULL
    for (i in 1:n) {
        tmp <- data.frame(x=rep(x.x[i], x.y[i]), y=1:x.y[i])
        x.final <- rbind(x.final, tmp)
    }
    plot(x.final, yaxt="n", ylab="", pch=19, frame.plot=FALSE, ...)
}

my.dot.plot(mydata, xlab ="speed", xlim=c(25,45))




More information about the R-help mailing list