library(ggplot2)
library(tidyr)
library(tibble)
library(scales)
#faili sisselugemine ja andmete formaadi korrigeerimine
J333=read.csv("PT3-T3.3-J3.3.3.csv",header=TRUE, encoding ="UTF-8")
J333=rownames_to_column(as.data.frame(t(J333)),"Vanus")
names(J333)[3:7]=J333[1,3:7]
names(J333)[2]="Heaolu"
J333=J333[2:5,]
J333$Vanus=c("8. klass","8. klass","11. klass", "11. klass")
J333$grupp=paste(J333$Vanus,J333$Heaolu)
J333=J333[,3:8]
J333=pivot_longer(J333,1:5)
J333$value=as.numeric(J333$value)
J333$grupp=as.factor(J333$grupp)
J333$grupp=factor(J333$grupp, levels(J333$grupp)[order(c(3,4,1,2))])
J333$name=as.factor(J333$name)
J333$name=factor(J333$name, levels(J333$name)[order(c(2,1,5,3,4))])
#joonis
ggplot(J333)+
geom_col(aes(x=name,y=value,fill=grupp),pos=position_dodge(0.8),width=0.7)+
theme_minimal()+
theme(legend.position = "bottom")+
scale_fill_manual(values=c("#1E272E","#0069AD","#4db3d9","#38bf7b"))+
theme(text = element_text(color="#668080"),axis.text=element_text(color="#668080"))+
scale_y_continuous(limits=c(0,4),breaks=c(0,1,2,3,4))+
theme(legend.title = element_blank())+
scale_x_discrete(labels = wrap_format(10))+
ylab("Keskmised hinnangud koolikeskkonna näitajatele")+
xlab("")
