Commit 6933432e authored by eudesyawog's avatar eudesyawog

adding ggplot script

parent c67be180
library(readr)
library(ggplot2)
library(ggthemes)
library(foreach)
library(scales)
library(dplyr)
csv=c("/home/je/Bureau/lab5/plots/niakhar_2017_radar_toggplot.csv","/home/je/Bureau/lab5/plots/niakhar_2017_radar_notree_toggplot.csv",
"/home/je/Bureau/lab5/plots/niakhar_2018_radar_toggplot.csv","/home/je/Bureau/lab5/plots/niakhar_2018_radar_notree_toggplot.csv",
"/home/je/Bureau/lab5/plots/nioro_2018_radar_toggplot.csv","/home/je/Bureau/lab5/plots/nioro_2018_radar_notree_toggplot.csv")
foreach(j=1:length(csv)) %do% {
df <- read.csv(csv[j], colClasses = c("Date","character","character","Date","Date","double","double"))
id<- unique(df$Plot)
outName <- unlist(strsplit(csv[j],"/"))[7]
outName <- gsub(".csv",".pdf",outName)
pdf(paste("/home/je/Bureau/lab5/plots/",outName,sep=""), width = 8.98, height = 5.86, title = "Plot mean")
foreach(i=1:length(id)) %do% {
plot <- df[which(df$Plot==id[i]),]
p <- ggplot(data=plot, aes(x=Date, y=Mean)) +
geom_vline(xintercept = unique(plot$Sowing), colour="grey50", size=1) +
geom_vline(xintercept = unique(plot$Harvest), colour="grey50", size=1) +
geom_point(aes(color=Band)) +
geom_line(aes(color=Band)) +
geom_ribbon(aes(ymin=Mean-Std,ymax=Mean+Std,fill=Band),alpha=0.2) +
ggtitle(plot$Plot) + ylab("Value") + theme_bw() +
scale_x_date(name="Time", breaks = date_breaks("months"),labels = date_format("%b")) +
theme(axis.text.x=element_text(size=15),
axis.text.y=element_text(size=15),
axis.title=element_text(size=18),
legend.title=element_text(size=18),
legend.text=element_text(size=15))
print(p)
}
dev.off()
}
csv=c("/home/je/Bureau/lab5/plots/niakhar_2017_opt_toggplot.csv","/home/je/Bureau/lab5/plots/niakhar_2017_opt_notree_toggplot.csv",
"/home/je/Bureau/lab5/plots/niakhar_2017_opt_gapf_toggplot.csv","/home/je/Bureau/lab5/plots/niakhar_2017_opt_gapf_notree_toggplot.csv",
"/home/je/Bureau/lab5/plots/niakhar_2018_opt_toggplot.csv","/home/je/Bureau/lab5/plots/niakhar_2018_opt_notree_toggplot.csv",
"/home/je/Bureau/lab5/plots/niakhar_2018_opt_gapf_toggplot.csv","/home/je/Bureau/lab5/plots/niakhar_2018_opt_gapf_notree_toggplot.csv",
"/home/je/Bureau/lab5/plots/nioro_2018_opt_toggplot.csv","/home/je/Bureau/lab5/plots/nioro_2018_opt_notree_toggplot.csv",
"/home/je/Bureau/lab5/plots/nioro_2018_opt_gapf_toggplot.csv","/home/je/Bureau/lab5/plots/nioro_2018_opt_gapf_notree_toggplot.csv")
foreach(j=1:length(csv)) %do% {
df <- read.csv(csv[j], colClasses = c("Date","character","character","Date","Date","double","double"))
df <- filter(df, Band %in% c("B2","B3","B4","B8","B5","B6","B7","B8A","B11","B12"))
id<- unique(df$Plot)
outName <- unlist(strsplit(csv[j],"/"))[7]
outName <- gsub(".csv","_Bands.pdf",outName)
pdf(paste("/home/je/Bureau/lab5/plots/",outName,sep=""), width = 8.98, height = 5.86, title = "Plot mean")
foreach(i=1:length(id)) %do% {
plot <- df[which(df$Plot==id[i]),]
p <- ggplot(data=plot, aes(x=Date, y=Mean)) +
geom_vline(xintercept = unique(plot$Sowing), colour="grey50", size=1) +
geom_vline(xintercept = unique(plot$Harvest), colour="grey50", size=1) +
geom_point(aes(color=Band)) +
geom_line(aes(color=Band)) +
geom_ribbon(aes(ymin=Mean-Std,ymax=Mean+Std,fill=Band),alpha=0.2) +
ggtitle(plot$Plot) + ylab("Value") + theme_bw() +
scale_x_date(name="Time", breaks = date_breaks("months"),labels = date_format("%b")) +
theme(axis.text.x=element_text(size=15),
axis.text.y=element_text(size=15),
axis.title=element_text(size=18),
legend.title=element_text(size=18),
legend.text=element_text(size=15))
print(p)
}
dev.off()
}
foreach(j=1:length(csv)) %do% {
df <- read.csv(csv[j], colClasses = c("Date","character","character","Date","Date","double","double"))
df <- filter(df, Band %in% c("NDVI","NDWI","CIGreen","CIRedEdge","EVI","MSAVI2","GDVI"))
id<- unique(df$Plot)
outName <- unlist(strsplit(csv[j],"/"))[7]
outName <- gsub(".csv","_Indices.pdf",outName)
pdf(paste("/home/je/Bureau/lab5/plots/",outName,sep=""), width = 8.98, height = 5.86, title = "Plot mean")
foreach(i=1:length(id)) %do% {
plot <- df[which(df$Plot==id[i]),]
p <- ggplot(data=plot, aes(x=Date, y=Mean)) +
geom_vline(xintercept = unique(plot$Sowing), colour="grey50", size=1) +
geom_vline(xintercept = unique(plot$Harvest), colour="grey50", size=1) +
geom_point(aes(color=Band)) +
geom_line(aes(color=Band)) +
geom_ribbon(aes(ymin=Mean-Std,ymax=Mean+Std,fill=Band),alpha=0.2) +
ggtitle(plot$Plot) + ylab("Value") + theme_bw() +
scale_x_date(name="Time", breaks = date_breaks("months"),labels = date_format("%b")) +
theme(axis.text.x=element_text(size=15),
axis.text.y=element_text(size=15),
axis.title=element_text(size=18),
legend.title=element_text(size=18),
legend.text=element_text(size=15))
print(p)
}
dev.off()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment