library(ggplot2)
library(tidyr)
library(scales)
#faili sisselugemine ja andmete formaadi korrigeerimine
J234=read.csv2("PT2-T2.3-J2.3.4.csv",header=TRUE, encoding ="UTF-8")
J234$X[1]="Drugs within 12 months"
J234$X[2]="Alcohol 4–7 days a week"
J234x=J234[1:8,]
J234y=J234[9:24,]
J234x=pivot_longer(J234x,2:5)
J234y=pivot_longer(J234y,2:5)
J234y$value=as.numeric(J234y$value)
J234x$high=J234y$value[1:32]
J234x$low=J234y$value[33:64]
J234=J234x
J234$value=as.numeric(J234$value)
J234$X=as.factor(J234$X)
J234$X=factor(J234$X,levels(J234$X)[order(c(2,8,4,3,6,7,5,1))])
J234$name=as.factor(J234$name)
J234$name=factor(J234$name,levels(J234$name)[order(c(3,1,4,2))])
#joonis
ggplot(J234,aes(x=X,y=value,col=name))+
geom_point(pos=position_dodge(0.8),cex=3)+
geom_errorbar(aes(ymin=value-low,ymax=value+high,col=name),width=0.3,pos=position_dodge(0.8),linewidth=0.9)+
geom_abline(intercept=1,slope=0)+
coord_flip()+
theme_minimal()+
theme(legend.title=element_blank())+
ylab("")+
xlab("")+
theme(axis.text.x = element_text(angle = 90),legend.position = "bottom")+
theme(text = element_text(color="#668080"),axis.text=element_text(color="#668080"))+
scale_color_manual(values=c("#668080","#FF3600","#f09d00","#6666cc"),breaks = rev(levels(J234$name)))
