Hi

thank you for talking the time to help me with this.

I have a sequence of numbers in a file and an equal sequence of various 
character, say(a b c d) each occurs more than once. I need to plot the numbers 
so that numbers corresponding to a in the other sequence would have green dots, 
those corresponding to b a red dot, nothing on c and blue square for d. i.e

2 a  show a green dot
4 b  show a red dot
8 b  show a red dot
6 c  show default colour
2 d  show blue square

I have the code below which plots the data but I have no clue how to inject the 
extra fancies.

****************************************************************
###########
# ploting #
###########
library(tkrplot)

#just the turning points 
L <- length(I0);                         #points to plot

tt <- tktoplevel()
left <- tclVar(1)
oldleft <- tclVar(1)
right <- tclVar(L)
cury <- tclVar(' ')
curx <- NA
tmpusr <- numeric(4)
tmpplt <- numeric(4)

f1 <- function(){
  lleft <- as.numeric(tclvalue(left))
  rright <- as.numeric(tclvalue(right))
  x <- seq(lleft,rright,by=1)
  par(bg='black', fg='green', col='white', col.axis='white',
      col.lab='magenta', col.main='blue', col.sub='cyan')
  plot(x,I0[x], type='s')

##   par(new=TRUE)
##   plot(x,I1[x], type='s', col='yellow',axes=F)
  
  par(new=TRUE)
  plot(x,I2[x], type='s', col='cyan',axes=F)

  axis(4)    
  tmpusr <<- par('usr')
  tmpplt <<- par('plt')

  if(!is.na(curx)){
    abline(v=curx, col='red', lty=2)
    abline(h=332, col='red', lty=2)
    points(curx,I0[curx],pch=16,col='red')
  }

}

img <- tkrplot(tt, f1,hscale=2,vscale=1.2)
tkconfigure(img, cursor='crosshair')

f2 <- function(...){
    ol <- as.numeric(tclvalue(oldleft))
    tclvalue(oldleft) <- tclvalue(left)
    r <- as.numeric(tclvalue(right))
    tclvalue(right) <- as.character(r + as.numeric(...) - ol)
    tkrreplot(img)
}

f3 <- function(...){
    tkrreplot(img)
}

f4 <- function(...){
  i <- 100
  ol <- as.numeric(tclvalue(oldleft))
  tclvalue(left) <- as.character(ol+i)
  tclvalue(oldleft) <- as.character(ol+i)
  r <- as.numeric(tclvalue(right))
  tclvalue(right) <- as.character(r+i)
  tkrreplot(img)
}

iw <- as.numeric(tcl('image','width', tkcget(img,'-image')))
ih <- as.numeric(tcl('image','height',tkcget(img,'-image')))

mm <- function(x,Y){
  tx <- (as.numeric(x)-1)/iw
  ty <- 1-(as.numeric(Y)-1)/ih
  
  if( tx > tmpplt[1] & tx < tmpplt[2] &
     ty > tmpplt[3] & ty < tmpplt[4] ){
    
    newx <- (tx-tmpplt[1])/(tmpplt[2]-tmpplt[1])*(tmpusr[2]-tmpusr[1])+tmpusr[1]
    curx <<- round(newx)
    tkrreplot(img)

    newy <- I0[curx]
    newy <- floor(newy) + (newy-floor(newy))*32/100

#    newy2 <- I1[curx]
    newy3 <- I2[curx]

    tclvalue(cury) <- paste('x =',curx,'  I0=',round(newy,2)
                            ,'  I2=',round(newy3,4))
  }
} 

tkbind(img, '<Motion>', mm)

l1 <- tklabel(tt, textvariable=cury)

s1 <- tkscale(tt, command=f2, from=1, to=length(I0),
    variable=left, orient="horiz",label='left',length=700)
s2  <- tkscale(tt, command=f3, from=1, to=length(I0),
    variable=right, orient="horiz",label='right',length=700)
b1 <- tkbutton(tt, text='->', command=f4)

tkpack(l1,img,s1,s2,b1)


 __________________________________________________



        [[alternative HTML version deleted]]

______________________________________________
R-help@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
and provide commented, minimal, self-contained, reproducible code.

Reply via email to