library(tidyr)
library(ggplot2)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
#faili sisselugemine ja andmete formaadi korrigeerimine
J133=read.csv2("PT1-T1.3-J1.3.3.csv",header=TRUE, encoding ="UTF-8")
J133$elugaRahulolu=as.numeric(J133$elugaRahulolu)
J133$matKesk=as.numeric(J133$matKesk)
J133$vrv="#6666cc"
J133$vrv[J133$Riik=="EESTI"]="#FF3600"
vrv=J133$vrv

#joonis
p=ggplot(J133,aes(x=elugaRahulolu,y=matKesk,label=Riik))+
  geom_point(col=vrv,cex=3)+
  geom_smooth(method="lm", linewidth=1,col="#FF3600",se=FALSE)+
  theme_minimal()+
  scale_x_continuous(breaks=c(6,6.5,7,7.5,8,8.5))+
  geom_text(aes(x=elugaRahulolu+0.05,y=matKesk+3,label=maaKood),col="#668080",cex=2.6)+
  theme(text = element_text(color="#668080"),axis.text=element_text(color="#668080"))+
  theme(legend.position = "none")+
  ylab("PISA matemaatika keskmine")+
  xlab("Eluga rahulolu")

ggplotly(p,tooltip=c("Riik"))
## `geom_smooth()` using formula = 'y ~ x'
## Warning: The following aesthetics were dropped during statistical transformation: label,
## x_plotlyDomain, y_plotlyDomain
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
##   the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
##   variable into a factor?