From maechler at stat.math.ethz.ch  Wed May 21 09:28:21 2008
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Wed, 21 May 2008 09:28:21 +0200
Subject: [Rd] need some help in plotting xy graph
In-Reply-To: <46404CB7389F1E4092DC68115C00B3EEC9D962@INEXC1U01.in.lucent.com>
References: <46404CB7389F1E4092DC68115C00B3EEC9D962@INEXC1U01.in.lucent.com>
Message-ID: <18483.53013.849003.70015@stat.math.ethz.ch>

1) If you need some help,  *PLEASE* use the R-help mailing list.

2) Sending your e-mail more than once (you sent it 3 times!) to
   the same mailing list of hundreds of subscribers
   is considered very impolite.


Martin Maechler, ETH Zurich, 
R-devel List manager

>>>>> "KR\" == Kurapati, Ravichandra \(Ravichandra\) <ravichandra.kurapati at alcatel-lucent.com>
>>>>>     on Wed, 21 May 2008 10:24:48 +0530 writes:

    KR\> Hi

 

    KR\> Dataframe    fdf contains

 

    KR\> bin rate                                                         overlay

    KR\> 1   1   90 Assign First/cc _from_SN_53 RNC_20_to_SN_50 RNC_21_Success
    KR\> Rate

    KR\> 2   2   93 Assign First/cc _from_SN_53 RNC_20_to_SN_50 RNC_21_Success
    KR\> Rate

    KR\> 3   1   90 Assign First/cc _from_SN_50 RNC_21_to_SN_53 RNC_20_Success
    KR\> Rate

    KR\> 4   2   94 Assign First/cc _from_SN_50 RNC_21_to_SN_53 RNC_20_Success
    KR\> Rate

    KR\> time

    KR\> 1 (04/01/08 16:02:30)

    KR\> 2 (04/01/08 16:07:30)

    KR\> 3 (04/01/08 16:02:30)

    KR\> 4 (04/01/08 16:07:30)

 

 

    KR\> And then I write the following lines of code to plot a xygraph on a pdf
    KR\> file 

 

 

    KR\> n <- length(unique(fdf$time))

    KR\> x <-sort(unique(fdf$time))

    KR\> y<-UTCsecs2chron(x)

 

 

    KR\> xscales <- computeTimeScales(y)

    KR\> yscales<-NULL

    KR\> scales<-c(xscales,yscales)

    KR\> ylab<-"session transfer rate"

    KR\> xlab<-"time"

    KR\> lgnd.txt<-levels(fdf$overlay)

 

    KR\> celnet.trellis.device(device="pdf", file="ravi_st.pdf", width=10,height
    KR\> = 10)

 

    KR\> main<-"this is the first report"

    KR\> formd="rate ~ as.numeric(time)"

    KR\> print(

    KR\> xyplot(formula(formd),

    KR\> data = fdf, groups = overlay,

    KR\> type = "b", as.table = TRUE, cex=0.20,

    KR\> #subset = ok, commented to show breaks in graph

    KR\> main = main, xlab = "Time", ylab = ylab,

    KR\> scales = scales,

    KR\> key = simpleKey(text = lgnd.txt, cex = 3/4,

    KR\> points = FALSE, lines = TRUE),

    KR\> page = function(n) annotate(opts$ann),

    KR\> sub = "",

    KR\> layout = c(1,1)

    KR\> )

 

    KR\> )

          

 

 

 

    KR\> "computeTimeScales" <-

    KR\> function(z, rot=0)  ## z is a chron object

    KR\> {browser()

    KR\> ## how many days do the data span?

    KR\> n.days <- ceiling(diff(range(z, na.rm = TRUE)))

 

    KR\> ## compute x ticks, pretty labels

    KR\> x <- as.numeric(z)

    KR\> r <- range(x, na.rm = TRUE)

    KR\> at.x <- seq(from = r[1], to = r[2], length = 7)

    KR\> two_digits <- function(x){

    KR\> x <- paste("0", x, sep="")

    KR\> substring(x,nchar(x)-1)

    KR\> }

 

    KR\> ## heuristics: use hh:mm when range of data falls within one day,

    KR\> ## otherwise use MM-DD hh:mm.

 

    KR\> at.z <- chron(at.x)

    KR\> hh <- paste(two_digits(hours(at.z)), two_digits(minutes(at.z)),
    KR\> sep=":")

    KR\> if(0){        ## hh:ss # this is commented as for more than one day
    KR\> from/to time no date was printed

    KR\> at.lbls <- hh

    KR\> }

    KR\> else {              ## MM-DD\nhh:ss

    KR\> m <- month.day.year(at.z)

    KR\> dd <- paste(two_digits(m$month), two_digits(m$day), sep="-")

    KR\> at.lbls <- paste(dd, hh, sep="\n")

    KR\> }

 

    KR\> list(x=list(at = at.x, rot=rot, labels = at.lbls))

    KR\> }

 

 

    KR\> "celnet.theme" <-

    KR\> function()

    KR\> {

    KR\> celnet.theme <- canonical.theme("pdf", color = TRUE)

    KR\> if(tolower(.Device) =="png")

    KR\> celnet.theme$background$col <- "white"

    KR\> else

    KR\> canonical.theme("pdf", color = TRUE)

    KR\> celnet.theme$background$col <- "transparent"

    KR\> celnet.theme

    KR\> }

 

    KR\> "celnet.trellis.device" <-

    KR\> function(device, file, width = NULL, height = NULL,...)

    KR\> {

    KR\> ## analogous to trellis.device() -- this is just tailored to Celnet

    KR\> if(is.null(width))

    KR\> width <- 8

    KR\> if(is.null(height))

    KR\> height <- 6

    KR\> if(tolower(device)=="png"){

    KR\> if(missing(width)) width <- 72 * width

    KR\> if(missing(height)) height <- 72 * height

    KR\> }

    KR\> if(tolower(device)=="x11")

    KR\> trellis.device(device, width=width, height=height,
    KR\> theme=celnet.theme())

    KR\> if(tolower(device)=="ps" || tolower(device)=="postscript")

    KR\> trellis.device("postscript", file=file,  color = TRUE,

    KR\> width=width, height=height, theme=celnet.theme())

    KR\> else

    KR\> trellis.device(device, file=file,

    KR\> width=width, height=height, theme=celnet.theme())

    KR\> }

 

    KR\> "annotate" <-

    KR\> function(str, ...)

    KR\> ## print a metadata message at the top-bottom of current trellis
    KR\> display

    KR\> { else if(n==1){

    KR\> x <- 0.95

    KR\> hjust <- "right"

    KR\> } else if(n==2){

    KR\> x <- c(0.05, 0.95)

    KR\> hjust <- c("left", "right")

    KR\> } else if(n==3){

    KR\> x <- c(0.05, 0.50, 0.95)

    KR\> hjust <- c("left", "center", "right")

    KR\> }

 

    KR\> x <- unit(x, "npc")

    KR\> y <- unit(1.5, "lines")        ## at 0.5, 1.5, ... lines

 

    KR\> for(i in seq(along = x)){

    KR\> grid.text(label = str[i],

    KR\> x = x[i], y = y, just = c(hjust[i], "bottom"), ...)

    KR\> }

    KR\> invisible(str)

    KR\> }

    KR\> n <- length(str)               ## one line per string

    KR\> if(n==0)

    KR\> return(invisible(str))

    KR\> }

 

 

                                                     

 

 

    KR\> But I did nt get any desired o/p on a file ravi_st.pdf

 

    KR\> Desired o/p is

    KR\> Rate ~ as.numeric(time)

    KR\> Group=overlay

    KR\> Can any one tell how can I get the desired o/p


    KR\> [[alternative HTML version deleted]]

    KR\> ______________________________________________
    KR\> R-devel at r-project.org mailing list
    KR\> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] need some help in plotting xy graph
Martin Maechler