library(ggplot2)
library(tidyr)

#faili sisselugemine ja andmete formaadi korrigeerimine
J524=read.csv2("PT5-T5.2-J5.2.4.csv",header=TRUE, encoding ="UTF-8")
names(J524)=gsub("X", " ",  names(J524))
J524=pivot_longer(J524,2:15)
J524$value=as.numeric(J524$value)
J524$name=as.numeric(J524$name)
J524$Saaste=as.factor(J524$Saaste)
J524$Saaste=factor(J524$Saaste,levels=rev(levels(J524$Saaste)))
J524$Piirkond=as.factor(J524$Piirkond)
J524$Piirkond=factor(J524$Piirkond, levels(J524$Piirkond)[order(c(3,4,1,2,5))])


#joonis
ggplot(J524)+
  geom_line(aes(x=name,y=value,col=Piirkond),linewidth=1.5)+
  facet_wrap(~Saaste,nrow=2)+
  theme_minimal()+
  scale_color_manual(values=c("#4026cc","#8fa300","#668080","#f09d00","#ff3600"))+
  theme(text = element_text(color="#668080"),axis.text=element_text(color="#668080"))+
  theme(strip.text.x = element_text(face = "bold",color="#668080"))+
  scale_x_continuous(breaks=unique(J524$name))+
  xlab("")+
  ylab("%")+
  theme(legend.title=element_blank(), legend.position = "top",)