|
代码让下:- library(ggplot2)
- library(grid)
- library(cowplot)
- rm(list = ls())
- #####################3
- x1 <- c(1:24)
- y1 <- rep(0,24)
- x2 <- c(1.01832,2.5111,3.29454,4.2111,5.56558,6.7779,7.69868,8.1116,8.54911,8.8719,10.502,11.624,12.6021,13.38369,14.6044,15.53498,16.79781,17.64545,18.7055,19.89457,21.28147,21.90863,22.92,23.79068)
- y2 <- c(0.49966,0.47829,0.52273,0.56164,0.20028,0.18676,0.04273,0.38412,0.53544,0.64607,0.98098,1.45222,1.54973,1.14462,1.23707,1.10624,1.18284,0.82722,0.85045,1.09494,0.74885,0.69401,0.89644,0.97778)
- s <- seq(length(x1))
- data <- data.frame(x1,x2,y1,y2)
- cp <- ggplot(data,aes(x=x1,y=y1))+geom_point(size=0)+
- geom_segment(aes(x = x1[s], y = y1[s], xend = x2[s], yend = y2[s]),size=1.5, arrow = arrow(length = unit(0.5, "cm")))+
- geom_hline(yintercept=0,linetype='dashed',color='blue',size=1)+
- ylab('wind-speed (m/s)')+xlab('Time (h)')+
- scale_y_continuous(limits=c(-4,4),breaks=c(-4.0,-2.0,0,2.0,4.0))+
- scale_x_continuous(limits=c(1,24),breaks=c(0,3,6,9,12,15,18,21,24))+theme_bw()+
- theme(panel.background=element_rect(fill='seagreen', color='black'),axis.text.x =element_blank(),axis.title.x=element_blank(),axis.ticks.x=element_blank() ,plot.margin = unit(c(0, 0.5, 0, 0.5), "lines"))
-
- #####################
- tep <- c(29.1,28.1,28,27.4,27.2,26.8,26.8,27.1,28.9,30.8,32.9,34,34.7,35.1,35.6,36.2,36.3,36.,35.8,34.5,32.8,31.8,31.3,30.8)
- rh <- c(75,78,77,77,78,80,80,80,72,64,54,50,49,49,47,45,45,47,49,54,61,66,68,71)
- tep1 <- data.frame(x1,tep)
- sp <- ggplot(tep1,aes(x=x1,y=tep))+geom_line(size=1.5,colour='red')+ylab('Tep (°C)')+xlab('Time (h)')+
- scale_x_continuous(limits=c(1,24),breaks=c(0,3,6,9,12,15,18,21,24))+
- geom_hline(yintercept=mean(tep),linetype='dashed',color='blue',size=1)+theme_bw()+
- theme(plot.background=element_rect(fill='lightblue', color='black'),
- axis.line.x=element_blank(),
- axis.ticks.length=unit(0, "cm") ,
- axis.ticks.margin=unit(0, 'lines'),
- axis.text.x =element_blank(),
- axis.title.x=element_blank(),
- axis.ticks.x=element_blank() ,
- plot.margin = unit(c(0, 0, 0, 0), "lines"),
- panel.margin = unit(0, "lines"),
- panel.border = element_rect(fill = NA, colour = "orange", size = 1),
- legend.position = "none"
- )
- ##############################3
- aqi <- c(19,59,119,118,87,67,126,216,217,179,186,300,298,309,319,320,319,220,221,150,120,100,119,119)
- aqi1 <- data.frame(x1,aqi)
- bp <- ggplot(aqi1,aes(x=x1,y=aqi))+geom_line(size=1.5,colour='blue')+ylab('pm')+xlab('Time (h)')+
- scale_x_continuous(limits=c(1,24),breaks=c(0,3,6,9,12,15,18,21,24))+
- scale_y_continuous(limits=c(0,500),breaks=c(0,50,100,150,200,300,500))+
- geom_hline(yintercept=100,linetype='dashed',color='orange',size=1)+theme_bw()+
- theme(plot.margin = unit(c(0.0, 1, 0, 0.5), "lines"))
- #print(grid.arrange(cp,sp,bp,ncol=1))
- ap <- plot_grid(cp,sp,bp,ncol=1,align='v')
- plot(ap)
复制代码
使用cowplot包将三个图像绘制在一起,但他们之间有缝隙,如何能让画出来的图像拼接在一起,我查了网上的一些画图区域设置,但是还是有一个空间在里面,请问哪个参数可以让第二幅图和第三幅图完美贴合在一起呢?
|