0

I have a problem for building barplot.

I am working on air traffic in different countries. I would like to get barplots for each countries with the different airport names in the X axis. The Y axis will show the quantity of airlines using the airport.

My plan is to make the script for 1 country and to replicate it manually for the others.

in my data, I have in the different columns: Country / aiport / destination. So each rows is actually one airline that is using the airport.

Do you have an idea about how to do this?

For now I have this idea:

UK<-traffic[traffic$Country=="UK",]

UK$airport <- as.factor(UK$airport)

countUK<-table(UK$airport)

barplot(countUK)

This is not working, I have a bunch of airports that are not in UK in the X axis...

Thanks for your help

talat
  • 62,625
  • 18
  • 110
  • 141
nif
  • 29
  • 1
  • 8
  • Please edit your question to include a minimal reproducible example. [See here for how to do this.](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Stephan Kolassa Dec 09 '14 at 09:37
  • You could try to drop unused factor levels, i.e. `UK – talat Dec 09 '14 at 09:47
  • possible duplicate of [dropping factor levels in a subsetted data frame in R](http://stackoverflow.com/questions/1195826/dropping-factor-levels-in-a-subsetted-data-frame-in-r) – talat Dec 09 '14 at 09:53

1 Answers1

0

Answer found:

You could try to drop unused factor levels, i.e.

UK <- droplevels(UK) after the line UK$airport <- as.factor(UK$airport).

talat
  • 62,625
  • 18
  • 110
  • 141
nif
  • 29
  • 1
  • 8