2017-06-15 98 views
-6

我期待重新下图: enter image description here在ggplot中,如何在同一个窗口中绘制多个图形?

我想不出我的生活如何把上述对方这样的图表。

任何帮助将不胜感激!

下面是数据的两个机场的样本:

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") 
+1

也许' facets'?你有尝试过什么吗? – Cath

+0

向我们显示您的代码。 – www

+3

方面是每一个像样的ggplot2教程的一部分。 – Roland

回答

2

以下应该工作,我已经存储在您的示例输入一个名为“逸”数据框:

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)) 
+0

谢谢,这是非常多的。我现在想知道如何重新排列收入群体。对此有何想法? – Chris

+0

看到这个问题:https://stackoverflow.com/questions/5208679/order-bars-in-ggplot2-bargraph –

相关问题