## 加载必要包和函数<br />
library(ggplot2)<br />
library(reshape2)<br />
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {<br />
# Multiple plot function<br />
#<br />
# ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects)<br />
# - cols: Number of columns in layout<br />
# - layout: A matrix specifying the layout. If present, 'cols' is ignored.<br />
#<br />
# If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE),<br />
# then plot 1 will go in the upper left, 2 will go in the upper right, and<br />
# 3 will go all the way across the bottom.<br />
#</p>
<p> require(grid)</p>
<p> # Make a list from the ... arguments and plotlist<br />
plots <- c(list(...), plotlist)</p>
<p> numPlots = length(plots)</p>
<p> # If layout is NULL, then use 'cols' to determine layout<br />
if (is.null(layout)) {<br />
# Make the panel<br />
# ncol: Number of columns of plots<br />
# nrow: Number of rows needed, calculated from # of cols<br />
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),<br />
ncol = cols, nrow = ceiling(numPlots/cols))<br />
}</p>
<p> if (numPlots==1) {<br />
print(plots[[1]])</p>
<p> } else {<br />
# Set up the page<br />
grid.newpage()<br />
pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))</p>
<p> # Make each plot, in the correct location<br />
for (i in 1:numPlots) {<br />
# Get the i,j matrix positions of the regions that contain this subplot<br />
matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))</p>
<p> print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,<br />
layout.pos.col = matchidx$col))<br />
}<br />
}<br />
}</p>
<p># ggplot2画图</p>
<p>a <- read.csv("C:\\Users\\user\\Desktop\\name_final.csv", header = TRUE)<br />
len<-dim(a)[1]<br />
c<- data.frame(a,time=1:len)</p>
<p>quotes_melt1<- melt(data=c,id.vars="time",measure=c("b1","u1","l1","b6","u6","l6","b8","u8","l8"))<br />
g1 <- ggplot(data=quotes_melt1,aes(x=time,y=value,color=variable))+geom_line()+theme(legend.position='none')+<br />
ggtitle("Historical Review")+theme(plot.title = element_text(lineheight=.8, face="bold"))<br />
g1 <- g1 + theme(axis.ticks = element_blank(), axis.text = element_blank())<br />
g1$labels$x <- " "<br />
g1$labels$y <- "Blg"</p>
<p>quotes_melt2<- melt(data=c,id.vars="time",measure="sd3")<br />
g2 <- ggplot(data=quotes_melt2,aes(x=time,y=value,color=variable))+geom_line()+theme(legend.position='none')<br />
g2 <- g2 + theme(axis.ticks = element_blank(), axis.text = element_blank())<br />
g2$labels$x <- " "<br />
g2$labels$y <- "sd"</p>
<p>quotes_melt3<- melt(data=c,id.vars="time",measure=c("wr4m4","wr4m9","wr4"))<br />
g3 <- ggplot(data=quotes_melt3,aes(x=time,y=value,color=variable))+geom_line()+theme(legend.position='none')<br />
g3 <- g3 + theme(axis.ticks = element_blank(), axis.text = element_blank())<br />
g3$labels$x <- "Time"<br />
g3$labels$y <- "Wil"</p>
<p>pdf("C:\\Users\\user\\Desktop\\name.pdf")<br />
print(multiplot(g1,g2,g3))<br />
dev.off()
根据这个代码画出的ggplot2图,具体要怎么对应修改,我试了试没成功
</p>