-6

I am looking to recreate the graph below: enter image description here

I can't figure out for the life of me how to put the charts above each other like this.

Any help would be much appreciated!

Here's a sample of the data for two of the airports:

structure(list(Income_group = c("Under 5750", "Under 5750", "5750 - 8624", 
"5750 - 8624", "8625 - 11499", "8625 - 11499", "11500 - 14374", 
"11500 - 14374", "14375 - 17249", "14375 - 17249", "17250 - 22999", 
"17250 - 22999", "23000 - 28749", "23000 - 28749", "28750 - 34499", 
"28750 - 34499", "34500 - 40249", "34500 - 40249", "40250 - 45999", 
"40250 - 45999", "46000 - 57499", "46000 - 57499", "57500 - 80499", 
"57500 - 80499", "80500 - 114999", "80500 - 114999", "115000 - 172999", 
"115000 - 172999", "173000 - 229999", "173000 - 229999", "over 230000", 
"over 230000", "Under 5750", "Under 5750", "5750 - 8624", "5750 - 8624", 
"8625 - 11499", "8625 - 11499", "11500 - 14374", "11500 - 14374", 
"14375 - 17249", "14375 - 17249", "17250 - 22999", "17250 - 22999", 
"23000 - 28749", "23000 - 28749", "28750 - 34499", "28750 - 34499", 
"34500 - 40249", "34500 - 40249", "40250 - 45999", "40250 - 45999", 
"46000 - 57499", "46000 - 57499", "57500 - 80499", "57500 - 80499", 
"80500 - 114999", "80500 - 114999", "115000 - 172999", "115000 - 172999", 
"173000 - 229999", "173000 - 229999", "over 230000", "over 230000"
), Trip_Type = c("business", "leisure", "business", "leisure", 
"business", "leisure", "business", "leisure", "business", "leisure", 
"business", "leisure", "business", "leisure", "business", "leisure", 
"business", "leisure", "business", "leisure", "business", "leisure", 
"business", "leisure", "business", "leisure", "business", "leisure", 
"business", "leisure", "business", "leisure", "business", "leisure", 
"business", "leisure", "business", "leisure", "business", "leisure", 
"business", "leisure", "business", "leisure", "business", "leisure", 
"business", "leisure", "business", "leisure", "business", "leisure", 
"business", "leisure", "business", "leisure", "business", "leisure", 
"business", "leisure", "business", "leisure", "business", "leisure"
), Airport = c("Gatwick", "Gatwick", "Gatwick", "Gatwick", "Gatwick", 
"Gatwick", "Gatwick", "Gatwick", "Gatwick", "Gatwick", "Gatwick", 
"Gatwick", "Gatwick", "Gatwick", "Gatwick", "Gatwick", "Gatwick", 
"Gatwick", "Gatwick", "Gatwick", "Gatwick", "Gatwick", "Gatwick", 
"Gatwick", "Gatwick", "Gatwick", "Gatwick", "Gatwick", "Gatwick", 
"Gatwick", "Gatwick", "Gatwick", "Heathrow", "Heathrow", "Heathrow", 
"Heathrow", "Heathrow", "Heathrow", "Heathrow", "Heathrow", "Heathrow", 
"Heathrow", "Heathrow", "Heathrow", "Heathrow", "Heathrow", "Heathrow", 
"Heathrow", "Heathrow", "Heathrow", "Heathrow", "Heathrow", "Heathrow", 
"Heathrow", "Heathrow", "Heathrow", "Heathrow", "Heathrow", "Heathrow", 
"Heathrow", "Heathrow", "Heathrow", "Heathrow", "Heathrow"), 
    percentage = c(1.1, 4.7, 0.8, 1.1, 1.1, 1.5, 1.1, 2.1, 2.4, 
    5, 2.8, 5.5, 6.6, 7.5, 8.9, 9.6, 12.6, 7.7, 10.7, 8.9, 11.3, 
    11.3, 15.6, 15.9, 13.6, 10.1, 6.8, 5.5, 2.2, 1.5, 2.4, 2.3, 
    0.7, 7.3, 0.5, 2.2, 0.9, 2, 1.1, 3, 1.1, 2.8, 3.1, 5.2, 4.2, 
    7.8, 7.2, 8.8, 8.2, 7.6, 10, 10.1, 12.8, 8.8, 18.3, 12.6, 
    14.2, 9.3, 9.6, 6.8, 3.5, 2.5, 4.6, 3.1)), .Names = c("Income_group", 
"Trip_Type", "Airport", "percentage"), row.names = 33:96, class = "data.frame")
Chris
  • 3,836
  • 1
  • 16
  • 34
  • 1
    maybe `facets`? have you tried anything? – Cath Jun 15 '17 at 13:42
  • Show us your code. – www Jun 15 '17 at 13:47
  • 3
    Facets are part of every decent ggplot2 tutorial. – Roland Jun 15 '17 at 13:57
  • 1
    Thanks for the comments. Admittedly I haven't tried anything beyond: `ggplot(df,aes(Income_group,percentage)) + geom_bar(stat="identity", position = "dodge")` due to not knowing where to start. Now I have a starting point, I'll try `facets` – Chris Jun 15 '17 at 13:59

1 Answers1

3

The following should work, I have stored your example input as a dataframe called 'dat':

library(ggplot2)
library(cowplot)

plt = ggplot(dat, aes(Income_group, percentage)) +
geom_bar(stat="identity") + facet_grid(Airport ~.) + background_grid(major = 'y', minor = "none") +
panel_border()

plt + theme(axis.text.x = element_text(angle = 90, hjust = 1))
user 123342
  • 463
  • 1
  • 9
  • 21