---
title: "Matematika 2 (2020/2021)"
author: "Damir Horvat"
date: "21/06/2021"
output: html_document
---

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

### Učitavanje paketa

```{r message=FALSE}
require(ggplot2)
require(dplyr)
require(tidyr)
```

### Učitavanje podataka

```{r warning=FALSE}
podaci <- read.csv("MAT2_2021.csv")
podaci$KOL.1 <- as.numeric(podaci$KOL.1)
podaci$KOL.2 <- as.numeric(podaci$KOL.2)
podaci$KOL.3 <- as.numeric(podaci$KOL.3)
podaci$Ocjena <- factor(podaci$OCJENA,levels = c("BP","1","2","3","4","5"))
podaciKOL <- podaci %>% select(KOL.1:KOL.3) %>% gather(kolokvij,bodovi)
```

### Raspodjela bodova na 1. kolokviju

```{r warning=FALSE}
ggplot(podaci, aes(x=KOL.1)) + 
  geom_histogram(binwidth = 1, color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  scale_x_continuous(name = "bodovi na 1. kolokviju", breaks = seq(0,21,2), limits = c(-1,21)) + 
  scale_y_continuous(name = "broj studenata", breaks = seq(0,40,2), limits = c(0,40)) +
  theme(panel.grid.minor.y = element_blank())
```

```{r warning=FALSE}
ggplot(podaci, aes(x=KOL.1)) + 
  geom_histogram(aes(y=..density..), binwidth = 1, color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  geom_vline(aes(xintercept=mean(KOL.1, na.rm = TRUE)),color="blue", linetype="dashed", size=0.5, alpha=0.3) +
  geom_density(alpha=.2, fill="yellow") +
  geom_rug() +
  scale_x_continuous(name = "bodovi na 1. kolokviju", breaks = seq(0,21,2), limits = c(-1,21)) + 
  scale_y_continuous(limits = c(0,0.15))
```

### Raspodjela bodova na 2. kolokviju

```{r warning=FALSE}
ggplot(podaci, aes(x=KOL.2)) + 
  geom_histogram(binwidth = 1, color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  scale_x_continuous(name = "bodovi na 2. kolokviju", breaks = seq(0,21,2), limits = c(-1,21)) + 
  scale_y_continuous(name = "broj studenata", breaks = seq(0,40,2), limits = c(0,40)) +
  theme(panel.grid.minor.y = element_blank())
```

```{r warning=FALSE}
ggplot(podaci, aes(x=KOL.2)) + 
  geom_histogram(aes(y=..density..), binwidth = 1, color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  geom_vline(aes(xintercept=mean(KOL.2, na.rm = TRUE)),color="blue", linetype="dashed", size=0.5, alpha=0.3) +
  geom_density(alpha=.2, fill="yellow") +
  geom_rug() +
  scale_x_continuous(name = "bodovi na 2. kolokviju", breaks = seq(0,21,2), limits = c(-1,21)) + 
  scale_y_continuous(limits = c(0,0.15))
```

### Raspodjela bodova na 3. kolokviju

```{r warning=FALSE}
ggplot(podaci, aes(x=KOL.3)) + 
  geom_histogram(binwidth = 1, color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  scale_x_continuous(name = "bodovi na 3. kolokviju", breaks = seq(0,21,2), limits = c(-1,21)) + 
  scale_y_continuous(name = "broj studenata", breaks = seq(0,40,2), limits = c(0,40)) +
  theme(panel.grid.minor.y = element_blank())
```

```{r warning=FALSE}
ggplot(podaci, aes(x=KOL.3)) + 
  geom_histogram(aes(y=..density..), binwidth = 1, color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  geom_vline(aes(xintercept=mean(KOL.3, na.rm = TRUE)),color="blue", linetype="dashed", size=0.5, alpha=0.3) +
  geom_density(alpha=.2, fill="yellow") +
  geom_rug() +
  scale_x_continuous(name = "bodovi na 3. kolokviju", breaks = seq(0,21,2), limits = c(-1,21)) + 
  scale_y_continuous(limits = c(0,0.15))
```

### Raspodjela bodova na sva tri kolokvija

```{r warning=FALSE}
ggplot(podaciKOL, aes(x=bodovi, fill=kolokvij, color=kolokvij)) + 
  geom_density(alpha=.2) +
  scale_x_continuous(name = "bodovi na kolokviju", breaks = seq(0,21,2), limits = c(-1,21)) + 
  scale_y_continuous( limits = c(0,0.15))
```

### Violina i boxplot svakog kolokvija

##### kvartili, aritmetička sredina

```{r warning=FALSE}
summary(podaci %>% select(KOL.1:KOL.3))
```

##### standardna devijacija

```{r warning=FALSE}
apply(podaci %>% select(KOL.1:KOL.3), 2, sd, na.rm=T)
```

```{r warning=FALSE}
ggplot(podaciKOL, aes(x=kolokvij, y=bodovi, fill=kolokvij)) +
  geom_dotplot(binaxis='y', stackdir='center', dotsize=0.2, fill='black', alpha=0.2, binwidth = 0.9) +
  geom_violin(trim=F, alpha=0.3) + geom_boxplot(width=0.05) + xlab('') +
  theme(axis.text.x=element_text(size=11), axis.text.y=element_text(size=11), legend.position='none')
```

### Raspodjela ukupnih bodova

```{r warning=FALSE}
ggplot(podaci, aes(x=UKUPNO)) + 
  geom_histogram(binwidth = 1, color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  scale_x_continuous(name = "ukupni bodovi", breaks = seq(0,100,5), limits = c(0,100)) + 
  scale_y_continuous(name = "broj studenata", breaks = seq(0,16)) +
  theme(panel.grid.minor = element_blank())
```

```{r warning=FALSE}
ggplot(podaci, aes(x=UKUPNO)) + 
  geom_histogram(aes(y=..density..), color="#ec8ae5", fill="#48d09b", alpha=0.5, 
                 breaks = c(0,20,50,61,75,91,100)) +
  geom_vline(aes(xintercept=mean(UKUPNO)),color="blue", linetype="dashed", size=0.5, alpha=0.3) +
  geom_density(alpha=.2, fill="yellow") +
  geom_rug() +
  scale_x_continuous(name = "ukupni bodovi", breaks = seq(0,100,5), limits = c(0,100)) +
  theme(panel.grid.minor.x = element_blank())
```

### Ocjene

```{r warning=FALSE}
ggplot(podaci, aes(x=factor(OCJENA))) +
  geom_bar(width=0.7, fill="steelblue") +
  geom_text(stat="count", aes(label=..count..), vjust=-0.5, nudge_x = -0.2, size = 3) +
  geom_text(aes( label = sprintf('(%s)', scales::percent(..prop..)), group = 1), stat= "count", 
            vjust = -.5, nudge_x = 0.15, size = 3) +
  scale_x_discrete(name = "Ocjena") +
  scale_y_continuous(name = "broj studenata", breaks = seq(0,150,10), limits = c(0,150))
```
