[R] dot diagram

Gabor Grothendieck ggrothendieck at gmail.com
Sun Apr 9 14:24:36 CEST 2006


Don't know about a function but it can be done in one plot statement
like this:

plot(seq(x) - match(x, x) ~ x, list(x = sort(mydata)),
	xlim=c(25,45), ylab ="", yaxt="n", pch=19, frame.plot=FALSE)

On 4/9/06, Jinsong Zhao <jszhao at mail.hzau.edu.cn> wrote:
> 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))
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list