---
title: "korelacije"
#author: "Damir Horvat"
#date: "10/31/2021"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

### Učitavanje paketa

```{r message=FALSE}
library(DT)
library(tidyverse)
library(readxl)
library(corrplot)
```

### Učitavanje podataka

```{r warning=FALSE}
podaci <- read_excel('podaci.xlsx', sheet=1)
imena <- names(podaci)
podaci <- podaci %>% rename_with(.fn = ~paste0("Q", substring(.,1,regexpr("\\.", .) - 1)), .cols = 9:length(imena))
pitanja <- podaci %>% select(Q1:Q67)
```

### Kodovi pitanja

```{r warning = FALSE}
kodovi_pitanja = data.frame(kod=names(pitanja), pitanje=imena[9:length(imena)])
datatable(
  kodovi_pitanja, extensions = c('Scroller'),
  options = list(deferRender = TRUE, scrollY = 200, scroller = TRUE))
```

### Korelacije među pitanjima (sve države)

```{r warning=FALSE}
korelacije <- round(cor(pitanja, use = "pairwise.complete.obs"), 2)
datatable(korelacije, filter = 'top',
    extensions = c('FixedColumns','Select', 'Buttons'),
    options = list(
      dom = 'Blfrtip',
      select = list(style = 'os', items = 'row'),
      buttons = c('selectAll', 'selectNone', 'selectRows', 'selectColumns', 'selectCells'),
      pageLength = 15,
      scrollX = TRUE,
      fixedColumns = TRUE
    )
)
```

```{r warning=FALSE, fig.width=15, fig.height=15}
corrplot(korelacije, type = "upper", tl.col = "black", tl.srt = 90, diag=FALSE, mar=c(0,0,6,0))
mtext("Sve države", at=18, cex=2, line=-45)
```

### Korelacije među pitanjima (Hrvatska)

```{r warning=FALSE}
pitanja_Croatia <- podaci %>% filter(Country == 'Croatia') %>% select(Q1:Q67)
korelacije_Croatia <- round(cor(pitanja_Croatia, use = "pairwise.complete.obs"), 2)
datatable(korelacije_Croatia, filter = 'top',
    extensions = c('FixedColumns','Select', 'Buttons'),
    options = list(
      dom = 'Blfrtip',
      select = list(style = 'os', items = 'row'),
      buttons = c('selectAll', 'selectNone', 'selectRows', 'selectColumns', 'selectCells'),
      pageLength = 15,
      scrollX = TRUE,
      fixedColumns = TRUE
    )
)
```

```{r warning=FALSE, fig.width=15, fig.height=15}
corrplot(korelacije_Croatia, type = "upper", tl.col = "black", tl.srt = 90, diag=FALSE, mar=c(0,0,6,0))
mtext("Hrvatska", at=18, cex=2, line=-45)
```

### Korelacije među pitanjima (Finska)

```{r warning=FALSE}
pitanja_Finland <- podaci %>% filter(Country == 'Finland') %>% select(Q1:Q67)
korelacije_Finland <- round(cor(pitanja_Finland, use = "pairwise.complete.obs"), 2)
datatable(korelacije_Finland, filter = 'top',
    extensions = c('FixedColumns','Select', 'Buttons'),
    options = list(
      dom = 'Blfrtip',
      select = list(style = 'os', items = 'row'),
      buttons = c('selectAll', 'selectNone', 'selectRows', 'selectColumns', 'selectCells'),
      pageLength = 15,
      scrollX = TRUE,
      fixedColumns = TRUE
    )
)
```

```{r warning=FALSE, fig.width=15, fig.height=15}
corrplot(korelacije_Finland, type = "upper", tl.col = "black", tl.srt = 90, diag=FALSE, mar=c(0,0,6,0))
mtext("Finska", at=18, cex=2, line=-45)
```

### Korelacije među pitanjima (Portugal)

```{r warning=FALSE}
pitanja_Portugal <- podaci %>% filter(Country == 'Portugal') %>% select(Q1:Q67)
korelacije_Portugal <- round(cor(pitanja_Portugal, use = "pairwise.complete.obs"), 2)
datatable(korelacije_Portugal, filter = 'top',
    extensions = c('FixedColumns','Select', 'Buttons'),
    options = list(
      dom = 'Blfrtip',
      select = list(style = 'os', items = 'row'),
      buttons = c('selectAll', 'selectNone', 'selectRows', 'selectColumns', 'selectCells'),
      pageLength = 15,
      scrollX = TRUE,
      fixedColumns = TRUE
    )
)
```

```{r warning=FALSE, fig.width=15, fig.height=15}
corrplot(korelacije_Portugal, type = "upper", tl.col = "black", tl.srt = 90, diag=FALSE, mar=c(0,0,6,0))
mtext("Portugal", at=18, cex=2, line=-45)
```

### Korelacije među pitanjima (Španjolska)

```{r warning=FALSE}
pitanja_Spain <- podaci %>% filter(Country == 'Spain') %>% select(Q1:Q67)
korelacije_Spain <- round(cor(pitanja_Spain, use = "pairwise.complete.obs"), 2)
datatable(korelacije_Spain, filter = 'top',
    extensions = c('FixedColumns','Select', 'Buttons'),
    options = list(
      dom = 'Blfrtip',
      select = list(style = 'os', items = 'row'),
      buttons = c('selectAll', 'selectNone', 'selectRows', 'selectColumns', 'selectCells'),
      pageLength = 15,
      scrollX = TRUE,
      fixedColumns = TRUE
    )
)
```

```{r warning=FALSE, fig.width=15, fig.height=15}
corrplot(korelacije_Spain, type = "upper", tl.col = "black", tl.srt = 90, diag=FALSE, mar=c(0,0,6,0))
mtext("Španjolska", at=18, cex=2, line=-45)
```
