library(ggplot2)
#faili sisselugemine ja andmete formaadi korrigeerimine
J224=read.csv("PT2-T2.2-J2.2.4.csv",header=FALSE, encoding ="UTF-8")
J224$V1[2]="Sex"
J224$V1[4:5]="Age"
J224$V1[7]="Home language"
J224$V1[9:10]="Family’s economic situation"
J224$V1=as.factor(J224$V1)
J224$V1=factor(J224$V1,c("Sex","Age","Home language","Family’s economic situation"))
J224$V2=as.factor(J224$V2)
J224$V2=factor(J224$V2,levels(J224$V2)[order(c(1,2,3,4,7,5,6,8,9,10))])
#joonis
ggplot(J224)+
facet_grid(~V1,scales="free")+
geom_col(aes(x=V2,y=V3,fill=interaction(V1,V2,sep=":")),pos=position_dodge(0.6),width=0.8)+
geom_text(aes(x=V2,y=V3+1,group=V1,label=paste(V3,"%",sep="")),fontface="bold",cex=3.5,col="#668080")+
theme_minimal()+
scale_fill_manual(values=c("#6666cc","#6666cc","#6666cc","#f09d00","#668080","#668080","#668080","#bf6900","#4026cc","#FF3600"))+
theme(text = element_text(color="#668080"),axis.text=element_text(color="#668080"))+
theme(strip.text.x = element_text(color="#668080"))+
theme(legend.position = "none")+
ylab("Share of young people")+
xlab("")
