0

The code creates a barplot comparing Delay Time and the Destination of various flights, but I have to alter it so it is in ascending order. I'm not sure whether to use order(), reorder(), etc.

tapply(df.delays$Delay,df.delays$Destination, sum)
totaldelay<-tapply(df.delays$Delay,df.delays$Destination, sum)
barplot(totaldelay, main="Total Delay Destination", xlab="Destination",ylab="Total Delay Time", ylim=c(0,25000))
  • 2
    You really need to post enough data to make a [minimum reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610), but generally you order with something like `sort(mtcars$hp)`, `mtcars[order(mtcars$hp)]`, or `dplyr::arrange(mtcars, cyl, hp)`, depending on what and how you want to order. – alistaire Feb 10 '16 at 05:02

1 Answers1

0

Try this (example for ?barplot):

require(grDevices) # for colours
tN <- table(Ni <- stats::rpois(100, lambda = 5))
r <- barplot(tN, col = rainbow(20))
#- type = "h" plotting *is* 'bar'plot
lines(r, tN, type = "h", col = "red", lwd = 2)

barplot(sort(tN), space = 1.5, axisnames = FALSE,
        sub = "barplot(..., space= 1.5, axisnames = FALSE)")
jrara
  • 16,239
  • 33
  • 89
  • 120