library(ggplot2)
library(tidyr)
library(scales)

#faili sisselugemine ja andmete formaadi korrigeerimine
J211=read.csv("PT2-T2.1-J2.1.1.csv",header=TRUE, encoding ="UTF-8")
names(J211)=J211[1,]
J211=J211[2:21,1:6]
tunnus=trimws(J211$Tunnus[c(1,3,5,7,12,14,17,19)])
J211=rbind(J211[c(2,4,6,8:11,13,15,16,18,20),])
J211$tunnusx=""
J211$tunnusx[1:3]=tunnus[1:3]
J211$tunnusx[4:7]=tunnus[4]
J211$tunnusx[8]=tunnus[5]
J211$tunnusx[9:10]=tunnus[6]
J211$tunnusx[11:12]=tunnus[7:8]
names(J211)[2]="OR"
J211$OR=as.numeric(J211$OR)
J211$LCI=as.numeric(J211$LCI)
J211$UCI=as.numeric(J211$UCI)
J211$tunnusx=as.factor(J211$tunnusx)
J211$tunnusx=factor(J211$tunnusx,levels=rev(levels(J211$tunnusx)[order(c(4,3,1,5,6,7,2,8))]))


#joonis
ggplot(J211)+
  facet_grid(tunnusx~.,scales="free",space="free")+
  geom_point(aes(x=Tunnus,y=OR,col=tunnusx),cex=3)+
  geom_errorbar(aes(x=Tunnus,ymin=LCI,ymax=UCI,col=tunnusx),width=0.2,linewidth=1)+
  geom_abline(slope=0,intercept=1,linewidth=0.1)+
  theme_minimal()+
  scale_color_manual(values=c("#668080", "#668080","#668080","#f09d00","#295200","#295200","#8fa300","#8fa300"))+
  theme(text = element_text(color="#668080"),axis.text=element_text(color="#668080"))+
  theme(legend.position = "none")+
  coord_flip()+
  xlab("")+
  ylab("Ĺ ansisuhe (OR)")+
  theme(strip.text.y = element_text(angle = 360,face="bold",color="#668080"))