Thanks to Greg Snow and John Kane I now have a working function that
does what I wanted, that is compares two scores in a plot.

Here is the function:

## compare.ratings: plots two lists corresponding to two different
## ratings. For each element, a line connects the position of that
## element in the two lists.

compare.ratings <- function(data.frame=df, vector1=rating1, vector2=rating2, 
vector3=labels) {
  treshold <- 0.1

  data.frame <- data.frame[sort.list(data.frame[[vector2]]),]
    
  for(i in 2:length(data.frame[,vector2])) {
     data.frame[i,vector2] <- data.frame[i,vector2] + (treshold * (i-1))
   }

  data.frame <- data.frame[sort.list(data.frame[[vector1]]),]
  
  for(i in 1:length(data.frame[,vector1])) {
    data.frame[i,vector1] <- data.frame[i,vector1] + (treshold * (i-1))
  }

  tmp <- c(rbind( data.frame[[vector1]], data.frame[[vector2]], NA ))
  tmp2 <- rep( c(1,2,NA), nrow(data.frame) )
 
  plot(tmp2, tmp, type='b', xlim=c(0,3), xlab='', ylab='', lwd=0.5)
  text(0.9, data.frame[[vector1]], data.frame[[vector3]], adj=1, cex=0.75)
  text(2.1, data.frame[[vector2]], data.frame[[vector3]], adj=0, cex=0.75)

}

-- 
Hans Ekbrand (http://sociologi.cjb.net) <[EMAIL PROTECTED]>
A. Because it breaks the logical sequence of discussion
Q. Why is top posting bad?

Attachment: signature.asc
Description: Digital signature

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to