#libraries library(reshape2) require(ggplot2) require(dplyr) setwd("C:/Users/qying/Google Drive/Chap1-2Analysis/sample_profile") f_in='samples.txt' table=read.table(f_in, header=TRUE, sep="\t") for (i in 1:nrow(table)) { sampleid=table[i,"id"] #reading data data<-read.table(file=paste0("txt/",sampleid,".txt"), header=FALSE, sep=",") #normalize to -1 - 1 data[6, ]<-data[6, ]/100 data[c(1:5,7), ]<-(data[c(1:5,7), ]-100)/100 colnames(data)<-c("bands",1999:2012) longdata<-melt(data,id.vars = "bands") ###### restructure the dataframe into a long format #plotting windows(2000,500) # connected, omitting NoData line<-ggplot(longdata,aes(variable,value,group=factor(bands))) + geom_line(aes(color=factor(bands)),size=1.5) + labs(x="Year",y="value") + scale_color_discrete(labels=c("b3","b4","b5","b7","min_NDVI","bare percent","nbr")) + theme(legend.title=element_blank()) line df<-read.table(file=paste0("txt/",sampleid,".txt"), header=FALSE, sep=",") data<-df[,-1] rownames(data)<-df[,1] #normalize to -1 - 1 data[6,]<-data[6,]/100 data[c(1:5,7),]<-(data[c(1:5,7),]-100)/100 line<-ggplot(data,aes(c(1999:2012),))+geom_line(aes(color="")) # g1<-ggplot(na.omit(data1), aes(interval, swir_norm))+ geom_line(aes(color="SWIR"), size=0.8) + geom_point(aes(color="SWIR"), size=3) + # scale_x_continuous(limits = c(0, 390), breaks=0+23*(0:16),expand=c(0,0))+ # scale_y_continuous(limits = c(0.75, 2), breaks=0.75+0.25*(0:5), expand=c(0,0))+ # labs(x=NULL, y=NULL)+ # annotate(geom = "text", x = 11.5 + 23 * (0:16), y = 0.8, label = (1999:2015), size=4) + # geom_line(aes(x = interval, y = ndvi, color="NDVI"), size=0.8) + geom_point(aes(x = interval, y = ndvi, color="NDVI"), size=3)+ # geom_line(aes(x = interval, y = ndwi, color="NDWI"), size=0.8) + geom_point(aes(x = interval, y = ndwi, color="NDWI"), size=3)+ # scale_colour_manual("", breaks = c("SWIR", "NDVI", "NDWI"), values=c("blue", "dark green", "red"))+ # theme( axis.text.x = element_blank(), panel.grid.minor.x=element_blank(), panel.grid.major.x=element_line(size=1)) #graph output ggsave(filename=paste0(sampleid,".tiff"), plot=line, dpi=150, compression="lzw") graphics.off() }