--- title: "regiviisid" output: html_document --- ```r library(tidyverse) ``` ``` ## Warning: package 'tidyverse' was built under R version 4.1.1 ``` ``` ## -- Attaching packages --------------------------------------- tidyverse 1.3.1 -- ``` ``` ## v ggplot2 3.3.5 v purrr 0.3.4 ## v tibble 3.1.5 v dplyr 1.0.7 ## v tidyr 1.1.4 v stringr 1.4.0 ## v readr 2.0.2 v forcats 0.5.1 ``` ``` ## Warning: package 'ggplot2' was built under R version 4.1.1 ``` ``` ## Warning: package 'tibble' was built under R version 4.1.1 ``` ``` ## Warning: package 'tidyr' was built under R version 4.1.1 ``` ``` ## Warning: package 'readr' was built under R version 4.1.1 ``` ``` ## Warning: package 'purrr' was built under R version 4.1.1 ``` ``` ## Warning: package 'dplyr' was built under R version 4.1.1 ``` ``` ## Warning: package 'stringr' was built under R version 4.1.1 ``` ``` ## Warning: package 'forcats' was built under R version 4.1.1 ``` ``` ## -- Conflicts ------------------------------------------ tidyverse_conflicts() -- ## x dplyr::filter() masks stats::filter() ## x dplyr::lag() masks stats::lag() ``` ```r noodid=read_csv("http://www.tlu.ee/~jaagup/andmed/muu/muusika/regiviisid.txt") ``` ``` ## Rows: 4941 Columns: 28 ``` ``` ## -- Column specification -------------------------------------------------------- ## Delimiter: "," ## chr (24): voti, alter, tugiheli, korgus, tempo, takt, P1, P2, P3, P4, P5, P6... ## dbl (3): IDviis, FKey, VNr ## lgl (1): Nr ``` ``` ## ## i Use `spec()` to retrieve the full column specification for this data. ## i Specify the column types or set `show_col_types = FALSE` to quiet this message. ``` P1 noodid sageduse järgi ```r noodid %>% group_by(P1) %>% summarise(kogus=n()) %>% arrange(-kogus) ``` ``` ## # A tibble: 105 x 2 ## P1 kogus ## ## 1 g 1151 ## 2 2d 827 ## 3 h 674 ## 4 2c 564 ## 5 a 560 ## 6 2e 203 ## 7 e 189 ## 8 f 144 ## 9 c 101 ## 10 d 97 ## # ... with 95 more rows ``` ```r noodid %>% filter(tugiheli=="g") %>% unite("kolmik", P1, P2, P3) %>% group_by(kolmik) %>% summarise(kogus=n()) %>% arrange(-kogus) %>% head(7) %>% .$kolmik -> kolmikud noodid %>% filter(tugiheli=="g") %>% mutate(kolmik=paste(P1, P2, P3, sep="_")) %>% filter(kolmik %in% kolmikud, P16 %in% c("g", "h", "d", "a")) %>% group_by(kolmik, P16) %>% summarise(kogus=n()) %>% arrange(-kogus) %>% ggplot(aes(kolmik, kogus)) + geom_col() + facet_wrap(~P16) ``` ``` ## `summarise()` has grouped output by 'kolmik'. You can override using the `.groups` argument. ``` ```r for( viimane in c("g", "a", "d", "h")){ print(viimane) joonis= noodid %>% filter(P16==viimane) %>% unite("kolmik", P1, P2, P3) %>% group_by(kolmik) %>% summarise(kogus=n()) %>% arrange(-kogus) %>% head(7) %>% ggplot(aes(kolmik, kogus)) + geom_col() print(joonis) } ``` ``` ## [1] "g" ``` ``` ## [1] "a" ``` ``` ## [1] "d" ``` ``` ## [1] "h" ``` ```r noodid=read_csv("http://www.tlu.ee/~jaagup/andmed/muu/muusika/regiviisid.txt") ``` ``` ## Rows: 4941 Columns: 28 ``` ``` ## -- Column specification -------------------------------------------------------- ## Delimiter: "," ## chr (24): voti, alter, tugiheli, korgus, tempo, takt, P1, P2, P3, P4, P5, P6... ## dbl (3): IDviis, FKey, VNr ## lgl (1): Nr ``` ``` ## ## i Use `spec()` to retrieve the full column specification for this data. ## i Specify the column types or set `show_col_types = FALSE` to quiet this message. ``` ```r metaandmed=read_csv("http://www.tlu.ee/~jaagup/andmed/muu/muusika/regiviisidmeta.txt") ``` ``` ## Rows: 4485 Columns: 43 ``` ``` ## -- Column specification -------------------------------------------------------- ## Delimiter: "," ## chr (31): kartoteek, viisiViide, tekstiViide, viisiKog, viisiKogA, tekstiKog... ## dbl (2): ID, top ## lgl (10): viisiKog_O, tekstiKog_O, kihelkond_tulnud, küla_tulnud, esitaja2, ... ``` ``` ## ## i Use `spec()` to retrieve the full column specification for this data. ## i Specify the column types or set `show_col_types = FALSE` to quiet this message. ``` ```r koos=metaandmed %>% inner_join(noodid, by=c("ID"="FKey")) noodid %>% filter(tugiheli=="g") %>% unite("kolmik", P1, P2, P3) %>% group_by(kolmik) %>% summarise(kogus=n()) %>% arrange(-kogus) %>% head(7) %>% .$kolmik -> kolmikud kolmikukogused=koos %>% mutate(kolmik=paste(P1, P2, P3, sep="_")) %>% filter(kolmik %in% kolmikud) %>% group_by(kihelkond, kolmik) %>% summarise(kogus=n()) %>% arrange(-kogus) ``` ``` ## `summarise()` has grouped output by 'kihelkond'. You can override using the `.groups` argument. ```