Dear R-Help, With the attached data set, I am still getting incorrect bwplots> xyplot(gdf$tt~gdf$OnHour |gdf$Runway, data=gdf) # Is correct> bwplot(gdf$tt~gdf$OnHour |gdf$Runway, data=gdf, horizontal=FALSE) #Puts the boxes on the wrong x-axis values # look especially at 0 and 3. How do I fix this? What is happening? Thanks, Jim Rome
Jim, Try this, bwplot(tt~as.factor(OnHour),data=gdf,......) Jun Shen from Millipore On Fri, Apr 16, 2010 at 3:54 PM, James Rome <jamesrome@gmail.com> wrote:> Dear R-Help, > > With the attached data set, I am still getting incorrect bwplots > > > xyplot(gdf$tt~gdf$OnHour |gdf$Runway, data=gdf) # Is correct > > > bwplot(gdf$tt~gdf$OnHour |gdf$Runway, data=gdf, horizontal=FALSE) # > Puts the boxes on the wrong x-axis values > # look especially at 0 and 3. How do I fix this? > > What is happening? > > Thanks, > Jim Rome > > > > ______________________________________________ > 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. > >[[alternative HTML version deleted]]
On 4/16/2010 8:27 PM, Jun Shen wrote:Jim, Try this, bwplot(tt~as.factor(OnHour),data=gdf,......) Jun Shen from Millipore I already tried using a factor, and the data set I enclosed had gdf$OnHFact which was already a factor. It gave the same wrong plot. What did work was to call xyplot instead of bwplot, and to use panel.bwplot in the panel function: hrs = seq(0, 23, 1) hrlabs = as.character(seq(0,23,1)) g = xyplot(gdf$tt~gdf$OnHour |gdf$Runway, data=gdf, ylab="Taxi time (min)", main=title, xlab="Hour of day", xlim=c(-1, 24), scales=list(x = list(rot=90, cex=.6, alternating=c(3,3,3,3), at=hrs, labels=hrlabs )), panel=function(x, ...) { panel.grid(h = -1, v = 24) panel.bwplot(x, horizontal=FALSE, col="black",...) } ) print(g) But I do not understand why this makes a difference. It has something to do with the fact that there are no data for some of the hours. The difference between the calls is either a bug, or it should be in the documentation somewhere obvious. I spent a week on this. Thanks, Jim Rome Thanks, Jim Rome
On Fri, Apr 16, 2010 at 1:54 PM, James Rome <jamesrome at gmail.com> wrote:> Dear R-Help, > > With the attached data set, I am still getting incorrect bwplotsNone of your attachments came through (presumably because of the list filters), and we need the data to figure out what's happening. Either put the result of dput inline (if it's not too big), or put it up somewhere we can download from. Putting a .txt extension may also work. -Deepayan>> xyplot(gdf$tt~gdf$OnHour |gdf$Runway, data=gdf) ? ? # Is correct > >> bwplot(gdf$tt~gdf$OnHour |gdf$Runway, data=gdf, horizontal=FALSE) ? # > Puts the boxes on the wrong x-axis values > # look especially at 0 and 3. How do I fix this? > > What is happening? > > Thanks, > Jim Rome > > > > ______________________________________________ > R-help at 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. > >
Ah, Well, I thought I put up just the data needed. Sorry, was wrong file. And yes I am still climbing up the very steep learning curve hill. I attach a better data set. If it gets stripped, it is at http://dl.dropbox.com/u/537118/gdf.txt 1. I put the gdf$tt~gdf$OnHour because in the rest of my code, there are other (previous and bigger) incarnations of this data frame with the same names. Or does the call automatically assume that the variable names are from the frame in the data= statement? How am I to know? 2. The plot you enclosed is still not correct. The 0 time things are plotted at 1. And I believe that there are no data at 3 am. That is why I asked the question, and I think this is also the key to the problem. 3. I did create factors as Jun suggested, and they are in OnHFact. But using OnHFact instead of OnHour also gives the wrong plot. The only thing that put the correct data on the correct hours was to call xyplot instead of bwplot, with panel.bwplot in the panel function. Sorry for being so dense, but I really find it much harder to read R documentation, than say, Java documentation. And I have 10 R books including R Graphics, which did not shed light on this issue either. Thanks for the help, Jim Rome On 4/17/10 9:52 AM, David Winsemius wrote:> After unzipping that file, http://dl.dropbox.com/u/537118/gdf.zip , I > got a structure object that took what seemed to be an inordinately > long time to eval-parse wehn assigned to gdf, but it did eventually > produce: > > > str(gdf) > 'data.frame': 2656 obs. of 21 variables: > $ OnDate :Class 'Date' num [1:2656] 14222 14221 14334 14424 > 14519 ... > $ FltOrigDt : chr "12/9/2008" "12/8/2008" "3/31/2009" > "6/29/2009" ... > $ MkdCrrCd : chr "DL" "DL" "DL" "DL" ... > $ MkdFltNbr : int 742 1517 1517 1517 1517 1699 1065 1777 1777 > 1777 ... > $ DprtTrpnStnCd : chr "DEN" "JAX" "JAX" "JAX" ... > $ ArrTrpnStnCd : chr "ATL" "ATL" "ATL" "ATL" ... > $ ActualOutLocal: POSIXct, format: "2008-12-09 01:04:00" "2008-12-08 > 05:37:00" "2009-03-31 05:32:00" ... > $ ActualOffLocal: POSIXct, format: "2008-12-09 01:47:00" "2008-12-08 > 06:11:00" "2009-03-31 05:43:00" ... > $ ActualOnLocal : POSIXct, format: "2008-12-09 06:10:00" "2008-12-08 > 06:56:00" "2009-03-31 06:33:00" ... > $ ActualInLocal : POSIXct, format: "2008-12-09 06:18:00" "2008-12-08 > 07:02:00" "2009-03-31 06:39:00" ... > $ ArrivalGate : Factor w/ 100 levels "A01","A02","A03",..: 2 2 2 2 > 2 2 2 2 2 2 ... > $ DepartureGate : chr "C44" "A7" "A7" "A10" ... > $ Flight : chr "DAL742" "DAL1517" "DAL1517" "DAL1517" ... > $ OnHour : chr "6" "6" "6" "6" ... > $ OnDateTime : POSIXct, format: "2008-12-09 06:10:00" "2008-12-08 > 06:56:00" "2009-03-31 06:33:00" ... > $ Runway : Factor w/ 10 levels "08L","08R","09L",..: 2 4 4 7 4 > 7 8 8 1 7 ... > $ Delay : int 15 8 NA NA NA NA NA NA NA NA ... > $ TaxiTime :Class 'difftime' atomic [1:2656] 480 360 360 240 > 360 420 300 300 540 780 ... > .. ..- attr(*, "units")= chr "secs" > $ passurdt : num 0 0 0 0 1 0 0 0 0 -7 ... > $ OnHFact : Ord.factor w/ 24 levels "0"<"1"<"2"<"3"<..: 7 7 7 7 > 7 8 8 13 13 12 ... > $ tt : num 8 6 6 4 6 7 5 5 9 13 ... > > > > On Apr 16, 2010, at 9:37 PM, James Rome wrote: > >> On 4/16/2010 8:27 PM, Jun Shen wrote:Jim, >> >> Try this, >> >> bwplot(tt~as.factor(OnHour),data=gdf,......) >> >> Jun Shen from Millipore >> >> I already tried using a factor, and the data set I enclosed had >> gdf$OnHFact which was already a factor. It gave the same wrong plot. >> >> What did work was to call xyplot instead of bwplot, and to use >> panel.bwplot in the panel function: >> >> hrs = seq(0, 23, 1) >> hrlabs = as.character(seq(0,23,1)) >> g = xyplot(gdf$tt~gdf$OnHour |gdf$Runway, data=gdf, > > This is a puzzling way to invoke xyplot and may have unforeseen > dangers. Generally when one uses a data argument to a plot function, > one does not also include that dataframe name in the formula terms on > either the LHS or the RHS. > >> ylab="Taxi >> time (min)", main=title, xlab="Hour of day", >> xlim=c(-1, 24), scales=list(x = list(rot=90, cex=.6, >> alternating=c(3,3,3,3), >> at=hrs, labels=hrlabs >> )), >> panel=function(x, ...) { >> panel.grid(h = -1, v = 24) >> panel.bwplot(x, horizontal=FALSE, col="black",...) >> >> } >> ) >> print(g) > > I took your initial code for a bwplot call and took out the extraneous > dataframe name in the formula terms and put in your axis code (with > more sensible formatting) and got what appears to be your desired plot: > > bwplot( tt~ OnHour |Runway, data=gdf, > scales=list(x = list(rot=90, cex=.6, > alternating=c(3,3,3,3), > at=hrs, labels=hrlabs > ) ), > horizontal=FALSE) > > Plot attached. > >> >> >> But I do not understand why this makes a difference. It has something to >> do with the fact that there are no data for some of the hours. > > I have not been able to figure out what you meant by "bars in the > wrong place". You could have been more forthcoming about what you saw > as the problem for the Readers of the list. My guess is that it has > something to do with not following the specified conventions for > arguments to the bwplot formula method. > > >> The difference between the calls is either a bug, or it should be in >> the documentation somewhere obvious. I spent a week on this. > > To report a bug you need a lot more specifics about your system and > better efforts at isolation to minimal cases. > >> >> Thanks, >> Jim Rome >> >> Thanks, >> Jim Rome >>-------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: gdf.txt URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100417/72714361/attachment.txt>
James Rome <jamesrome <at> gmail.com> writes:> ... does the call automatically assume that the variable > names are from the frame in the data= statement?Yes, it does. How about bwplot(tt~factor(OnHour,levels=0:23)|Runway,data=gdf, drop.unused.levels=FALSE) ?
David, I did post a solved message: hrs = seq(0, 23, 1) hrlabs = as.character(seq(0,23,1)) g = xyplot(gdf$tt~gdf$OnHour |gdf$Runway, data=gdf, ylab="Taxi time (min)", main=title, xlab="Hour of day", xlim=c(-1, 24), scales=list(x = list(rot=90, cex=.6, alternating=c(3,3,3,3), at=hrs, labels=hrlabs )), panel=function(x, ...) { panel.grid(h = -1, v = 24) panel.bwplot(x, horizontal=FALSE, col="black",...) } ) print(g) created the plot I sent you (withxyplot.png), with the 0 data plotted on zero, and the 3AM data blank. I arrived at this by doing xyplot and observing that the points were plotted correctly. Then I added panel.bwplot() and it was still correct, so I removed panel.xyplot() and it worked. But replacing the main call to xyplot with bwplot gets it wrong. For example, I did it with hrs = seq(0, 23, 1) hrlabs = as.character(seq(0,23,1)) g = bwplot(gdf$tt~gdf$OnHFact |gdf$Runway, data=gdf, ylab="Taxi time (min)", main=title, xlab="Hour of day", xlim=c(-1, 24), horizontal=FALSE, drop.unused.levels=FALSE, scales=list(x = list(rot=90, cex=.6, alternating=c(3,3,3,3), at=hrs, labels=hrlabs )), panel=function(x, ...) { panel.grid(h = -1, v = 24) panel.bwplot(x, col="black",...) } ) print(g) and get the attached withbwplotAndFactors.png, which is wrong. It was also wrong with OnHour, and with drop.unused.levels=TRUE. And I did indeed get errors if I left the gdf$ out of the formulas, because it is defined in many data frames. Thanks, Jim On 4/17/2010 12:35 PM, David Winsemius wrote: On Apr 17, 2010, at 12:29 PM, James Rome wrote:> It has all the data needed, and only that data, which I got dinged on > before.I was seeing a different number of points in some panels in your plot compared to my plot. I have not downloaded the most recent dataset, and from what you are saying here should I assume it had not changed? But your plot had a title that could not have been created by the posted code , so i just don't know where you are with all of this. Are you going to post a SOLVED message when it is finally answered? -------------- next part -------------- A non-text attachment was scrubbed... Name: withbwplotAndFactors.PNG Type: image/png Size: 52267 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100417/a43faeeb/attachment.png> -------------- next part -------------- A non-text attachment was scrubbed... Name: withxyplot.PNG Type: image/png Size: 52179 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100417/a43faeeb/attachment-0001.png>