在ggplot中对齐多个图

时间:2013-10-15 23:57:38

标签: r ggplot2

我一直在使用R和ggplot研究一些流行病学数据。我使用以下代码绘制了人口金字塔:

使用here中的多重绘图脚本提供数据here

plot1 <- ggplot(pt.indig, aes(x=agecat, fill=gender)) +
   geom_bar(position="dodge") +
   scale_fill_brewer("Gender", palette="Set1") + 
   scale_y_continuous(breaks=c(0:10), minor_breaks=NULL) + coord_flip() +
   labs(y="Indigenous Patients", x=NULL) + coord_flip() +
   theme_bw() + theme(axis.text.y=element_text(hjust=-0.1))

plot2 <- ggplot(pt.nind, aes(x=agecat, fill=gender)) + 
   geom_bar(aes(y=..count..*(-1)), position="dodge") +
   scale_fill_brewer(palette="Set1") + coord_flip() + 
   scale_y_continuous(breaks=seq(-11,0,1), labels=abs(seq(-11,0,1))) +
   labs(x=NULL, y="Non-Indigenous Patients") + 
   theme(legend.position="none", axis.text.y=element_blank(), axis.ticks.y=element_blank())

multiplot(plot2, plot1, cols=2)

生成此图表: poppyr

我想用图表做的是:

  1. 使两个图的相对大小相同
    • 水平,因此条形成比例
    • 垂直,以便年龄类别正确排列
  2. 将左侧图形移近y轴标签(或标签) 跨越,但使用hjust取代较短的标签(NA,和 &lt; 10岁的标签))
  3. 使非indig 10-14岁的男性酒吧节目与其他人一样宽
  4. (理想情况下,使NA条形颜色相同,但不如其他颜色重要)
  5. 非常感谢。

0 个答案:

没有答案
相关问题