library(ggplot2)
library(tidyr)

#faili sisselugemine ja andmete formaadi korrigeerimine
J315=read.csv2("PT3-T3.1-J3.1.5.csv",header=TRUE, encoding ="UTF-8")
## Warning in read.table(file = file, header = header, sep = sep, quote = quote, :
## incomplete final line found by readTableHeader on 'PT3-T3.1-J3.1.5.csv'
names(J315)[4]="X10.aastased.üksikvanemaga.perest"
names(J315)[7]="X12.aastased.üksikvanemaga.perest"
J315=pivot_longer(J315, 2:7)
J315$name=sub("X", "",J315$name)
J315$name=sub("10.", "10-",J315$name)
J315$name=sub("12.", "12-",J315$name)
J315$name=sub("\\.", " ",J315$name)
J315$name=sub("\\.", " ",J315$name)
J315$name=sub("\\.", " ",J315$name)
J315$value=as.numeric(J315$value)

J315$name=as.factor(J315$name)
J315$Riik=as.factor(J315$Riik)



#joonis
ggplot(J315)+
  facet_grid(~Riik)+
  geom_col(aes(x=name,y=value,fill=name))+
  geom_label(aes(x=name, y=value, label=value))+
  theme_minimal()+
  theme(legend.position = "bottom")+
  scale_fill_manual(values=c("#1E272E","#6666cc","#0069AD","#4db3d9","#81DBFE","#e0e8d6"))+
  theme(text = element_text(color="#668080"),axis.text=element_text(color="#668080"))+
  theme(strip.text.x=element_text(color="#668080"))+
  scale_y_continuous(limits=c(0,10))+
  theme(axis.text.x = element_blank(),legend.title = element_blank())+
  guides(fill = guide_legend(nrow=3,byrow = TRUE))+
  ylab("")+
  xlab("")