在R中分割一个图

时间:2016-07-10 01:56:41

标签: r plot ggplot2

如何将图表拆分为两个图表?我一直在使用这段代码

ggplot(maris,aes(x=reorder(Municipio,Municipio,function(x)-length(x)))) +
       ggtitle("Municipios") + geom_bar(fill="red",colour="black") +
       theme(axis.text=element_text(size=12,angle = -90, hjust = 1),
             axis.title=element_text(size=14,face="bold",)) 

maris是我的数据集,Municipio是我想要绘制的内容,但有超过300个结果,您无法在图表中清楚地看到它。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

你可以通过一些价值来分析数据。在这里,我使用facet_wrap按字母顺序拆分了一些数据

ggplot(data.frame(month.name, y = rnorm(12), b = substr(month.name,1,1)<"m"), aes(month.name, y)) +
  geom_bar(stat = "identity") + 
  facet_wrap(~b, ncol = 1, scales = "free_x")

您可能希望更改主题以删除构面标签。