只要給一些名字每一個情節,然後用grid.arrange()
功能如下:
p1<-ggplot(e,aes(a,b/max(b)*100))
+geom_step(lwd=1.2,direction="hv",colour="black")
+ annotate(geom="rect", xmin
=0,xmax=160/60,ymin=0,ymax=100,alpha=.4,fill="green")
+annotate(geom="rect", xmin =160/60,xmax=779/60+160 /60,ymin=0,ymax=100,alpha=.4,fill="blue")
+ggtitle("Départ HTA MARCEAU DR 8A 25/11/2016")
+ylab("%Clients coupés")+xlab("Durées d'interruptions (en h)")
+annotate("text", x=c(1.5,10),y=c(70,80), label=c("Localisation","Dépannage"))
+ geom_vline(xintercept = (0/3600),col = c("red"))
+geom_vline(xintercept = (2475/3600),col = c("blue"),show.legend=TRUE)
+geom_vline(xintercept = (939/60+2475/3600+13/60))
Similarly define p2,p3,p4... as many plots you have
Then use following:
library(gridExtra)
grid.arrange(p1,p2,p3,p4,ncol=2)
更新
ggplot() #define first plot
+geom_step(e,aes(a,b/max(b)*100),lwd=1.2,direction="hv",colour="black")
+ annotate(geom="rect", xmin =0,xmax=160/60,ymin=0,ymax=100,alpha=.4,fill="green")
+annotate(geom="rect", xmin =160/60,xmax=779/60+160 /60,ymin=0,ymax=100,alpha=.4,fill="blue")
+ggtitle("Départ HTA MARCEAU DR 8A 25/11/2016")
+ylab("%Clients coupés")+xlab("Durées d'interruptions (en h)")
+annotate("text", x=c(1.5,10),y=c(70,80), label=c("Localisation","Dépannage"))
+ geom_vline(xintercept = (0/3600),col = c("red"))
+geom_vline(xintercept = (2475/3600),col = c("blue"),show.legend=TRUE)
+geom_vline(xintercept = (939/60+2475/3600+13/60))
#2nd plot
+geom_step(e,aes(a,b/max(b)*100),lwd=1.2,direction="hv",colour="black")
+ annotate(geom="rect", xmin =0,xmax=160/60,ymin=0,ymax=100,alpha=.4,fill="green")
+annotate(geom="rect", xmin =160/60,xmax=779/60+160 /60,ymin=0,ymax=100,alpha=.4,fill="blue")
+ggtitle("Départ HTA MARCEAU DR 8A 25/11/2016")
+ylab("%Clients coupés")+xlab("Durées d'interruptions (en h)")
+annotate("text", x=c(1.5,10),y=c(70,80), label=c("Localisation","Dépannage"))
+ geom_vline(xintercept = (0/3600),col = c("red"))
+geom_vline(xintercept = (2475/3600),col = c("blue"),show.legend=TRUE)
+geom_vline(xintercept = (939/60+2475/3600+13/60))
等..
使用'dput添加重複的例子( )'左右。但看看'facet_wrap()'。 – Jimbou
請參閱http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example瞭解如何提供可重現的數據。對於數據可視化問題,一個圖或示例的模型將幫助我們理解您試圖實現的是什麼。 –