Preliminary visual exploration of data. > Click code to see how it was done
The data comes from samples collected as spraints: Each of them was analysed under the microscope, bones and scales identified whenever possible. Fish bones were measured and gave us the size group of the individual.
The aim of the study is to show the variability of the otter diet, both in terms of size and biodiversity.
The studied locations are:
We would expect to find differences in predation between lakes and rivers, between upper and lower courses of the rivers, and also between the two lakes, as Milada was much more recently formed than Přísečnice.
Predation should reflect the size distribution and availability of each species, so we should be able to see differences in the size distribution between stocked fish (Salmonids) and wild fish, such as Gobio sp.
Original data in wide format: One column for each observation of species and each size category
# Data----
path <- here::here("data", "krusnehory.xlsx")
raw <- path %>%
excel_sheets() %>%
set_names() %>%
map_df(read_excel, #join all sheets by row
path = path,
.id = "location") %>% #create new column with the name of the sheets
clean_names() #probably many errors, so better clean
head(raw)
## # A tibble: 6 x 213
## location stretch month season abramis alburnoides_bipuncta~ alburnus_alburn~
## <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
## 1 Bílina dolní April spring 0 0 0
## 2 Bílina dolní August summer 0 0 0
## 3 Bílina dolní Februa~ winter 1 4 4
## 4 Bílina dolní January winter 1 0 0
## 5 Bílina dolní July summer 0 0 0
## 6 Bílina dolní March spring 0 0 0
## # ... with 206 more variables: anguilla_anguilla <dbl>,
## # barbatula_barbatula <dbl>, barbus_barbus <dbl>, blicca_bjoerkna <dbl>,
## # carassius <dbl>, cottus <dbl>, ctenopharyngodon <dbl>, cyprinidae <dbl>,
## # cyprinus_carpio <dbl>, esox_lucius <dbl>, gobio <dbl>,
## # gasterosseus_aculeatus <dbl>, gymnocephalus <dbl>,
## # chondrostoma_nasus <dbl>, ictalurus_nebulosus <dbl>, ic_neb_5_10_cm <dbl>,
## # ic_neb_10_15_cm <dbl>, lepomis_gibbosus <dbl>, leucaspius_delineatus <dbl>,
## # leuciscus_cephalus <dbl>, leuciscus_leuciscus <dbl>, lota_lota <dbl>,
## # misgurnus_fosilis <dbl>, neogobius_melanostomus <dbl>,
## # oncorhynchus_mykkiss <dbl>, perca_fluviatilis <dbl>,
## # phoxinus_phoxinus <dbl>, pseudorasbora_parva <dbl>, rhodeus_sericeus <dbl>,
## # rutilus_rutilus <dbl>, salmonids <dbl>, salmo_trutta_fario <dbl>,
## # scardinius_erythrophtalmus <dbl>, silurus_glanis <dbl>, tinca_tinca <dbl>,
## # astacus <dbl>, molusca <dbl>, coleoptera <dbl>, odonata_larvae <dbl>,
## # insecta <dbl>, anura <dbl>, aves <dbl>, mammalia <dbl>, caudata <dbl>,
## # serpentes <dbl>, al_bi_5_10_cm <dbl>, al_bi_10_15_cm <dbl>,
## # al_al_0_5_cm <dbl>, al_al_5_10_cm <dbl>, al_al_10_15_cm <dbl>,
## # ba_ba_5_10_cm <dbl>, ba_ba_10_15_cm <dbl>, ba_ba_15_20_cm <dbl>,
## # br_br_5_10_cm <dbl>, br_br_10_15_cm <dbl>, br_br_15_20_cm <dbl>,
## # br_br_20_25_cm <dbl>, br_br_25_30_cm <dbl>, br_br_30_35_cm <dbl>,
## # br_br_35_40_cm <dbl>, br_br_40_45_cm <dbl>, ca_5_10_cm <dbl>,
## # ca_10_15_cm <dbl>, ca_15_20_cm <dbl>, ca_20_25_cm <dbl>, ca_25_30_cm <dbl>,
## # ca_30_35_cm <dbl>, ca_35_40_cm <dbl>, cg_5_10_cm <dbl>, cg_10_15_cm <dbl>,
## # cy_0_5_cm <dbl>, cy_5_10_cm <dbl>, cy_10_15_cm <dbl>, cy_15_20_cm <dbl>,
## # cy_20_25_cm <dbl>, cy_25_30_cm <dbl>, cy_30_35_cm <dbl>, cy_35_40_cm <dbl>,
## # cy_40_45_cm <dbl>, el_0_5_cm <dbl>, el_5_10_cm <dbl>, el_10_15_cm <dbl>,
## # el_15_20_cm <dbl>, el_20_25_cm <dbl>, el_25_30_cm <dbl>, el_30_35_cm <dbl>,
## # el_35_40_cm <dbl>, gg_0_5_cm <dbl>, gg_5_10_cm <dbl>, gg_10_15_cm <dbl>,
## # gg_15_20_cm <dbl>, gy_5_10_cm <dbl>, gy_10_15_cm <dbl>,
## # ch_na_5_10_cm <dbl>, ch_na_10_15_cm <dbl>, ch_na_15_20_cm <dbl>,
## # ch_na_20_25_cm <dbl>, ch_na_25_30_cm <dbl>, ch_na_30_35_cm <dbl>,
## # le_del_0_5_cm <dbl>, ...
Before the analysis we need to:
# What a mess. Let's try to tidy it.
#
# 1) separate all those columns with sizes from the species.
# 2) pivot sizes into a single column
# 3) filter by initials, add a species column for the fish with size, one by one. FUck.
tidy_size <- raw %>%
dplyr::select(location, stretch, month, season, contains("_cm")) %>%
pivot_longer(
cols = contains("cm"),
names_to = "size",
values_to = "number",
values_drop_na = TRUE
) %>% #join later with new species column below
# levels(as.factor(tidy_size$size)) # how many different sizes? jooooder
# Better redo the following code nightmare with case_when()!!
dplyr::mutate(species = ifelse(
grepl("al_bi_", size),
"Alburnoides bipunctatus",
ifelse(
grepl("al_al_", size),
"Alburnus alburnus",
ifelse(
grepl("st_tr_", size), #looks like a typing error
"Salmo trutta m. fario",
ifelse(
grepl("ab_br_", size),
"Abramis sp.",
ifelse(
grepl("ba_ba_", size),
"Barbatula barbatula",
ifelse(
grepl("br_br_", size),
"Barbus barbus",
ifelse(
grepl("ca_", size),
"Carassius sp.",
ifelse(
grepl("cg_", size),
"Ctenopharyngodon idella",
ifelse(
grepl("cy_", size),
"Cyprinus carpio",
ifelse(
grepl("ct_id_", size),
"Ctenopharyngodon idella",
ifelse(
grepl("ga_ac", size),
"Gasterosteus aculeatus",
ifelse(
grepl("ch_na_", size),
"Chondrostoma nasus",
ifelse(
grepl("el_", size),
"Esox lucius",
ifelse(
grepl("gg_", size),
"Gobio a Romanogobio sp.",
ifelse(
grepl("gy_", size),
"Gymnocephalus cernua",
ifelse(
grepl("ic_neb_", size),
"Ictalurus nebulosus",
ifelse(
grepl("le_ce_", size),
"Squalius cephalus",
ifelse(
grepl("le_del_", size),
"Leucaspius delineatus",
ifelse(
grepl("le_gi_", size),
"Lepomis gibbosus",
ifelse(
grepl("le_le_", size),
"Leuciscus leuciscus",
ifelse(
grepl("lo_lo_", size),
"Lota lota",
ifelse(
grepl("mi_fo_", size),
"Misgurnus fosilis",
ifelse(
grepl("neog_mel_", size),
"Neogobius melanostomus",
ifelse(
grepl("on_myk_", size),
"Oncorhynchus mykiss",
ifelse(
grepl("pf_", size),
"Perca fluviatilis",
ifelse(
grepl("ph_ph_", size),
"Phoxinus phoxinus",
ifelse(
grepl("pp_", size),
"Pseudorasbora parva",
ifelse(
grepl("rs_", size),
"Rhodeus sericeus",
ifelse(
grepl("rr_", size),
"Rutilus rutilus",
ifelse(
grepl("sa_", size),
"Salmonids",
ifelse(
grepl("se_", size),
"Scardinius erythrophtalmus",
ifelse(
grepl("si_gl_", size),
"Silurus glanis",
ifelse(
grepl("sl_tr_", size),
"Salmo trutta m. fario",
ifelse(
grepl("st_luc_", size),
"Stizostedion lucioperca",
ifelse(grepl("tt_", size), "Tinca tinca", "error") #adding option for error in case I missed a name
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
))
head(tidy_size)
## # A tibble: 6 x 7
## location stretch month season size number species
## <chr> <chr> <chr> <chr> <chr> <dbl> <chr>
## 1 Bílina dolní April spring ic_neb_5_10_cm 0 Ictalurus nebulosus
## 2 Bílina dolní April spring ic_neb_10_15_cm 0 Ictalurus nebulosus
## 3 Bílina dolní April spring al_bi_5_10_cm 0 Alburnoides bipunctatus
## 4 Bílina dolní April spring al_bi_10_15_cm 0 Alburnoides bipunctatus
## 5 Bílina dolní April spring al_al_0_5_cm 0 Alburnus alburnus
## 6 Bílina dolní April spring al_al_5_10_cm 0 Alburnus alburnus
########################## PREVIOUS ATTEMPTS, DON'T RUN ######################
# pivot_longer(
# cols = Abramis:"Stizostedion lucioperca",
# names_to = "species",
# values_to = "numberPrey",
# values_drop_na = TRUE
# )
#
#
#
#
# pivot_longer(
# cols = contains("cm"),
# names_to = "size",
# values_to = "number",
# values_drop_na = TRUE
# ) %>% # nooooooooo! hay que hacerlo manual, cada size with its species
# dplyr::filter(number > 0) %>%
# dplyr::mutate(size = str_remove_all(size, "[*a-zA-Z]")) %>% #fuck regular expressions
# dplyr::mutate (size = glue("{size}cm")) %>% #had to install dev version of dplyr
# dplyr::mutate(size = str_trim(size)) %>% #remove extra space
# dplyr::mutate(size = fct_relevel(size, "5-10 cm", after = 1)) %>%
# uncount(number) %>% # to get individual observations!!
# pivot_longer(
# cols = Abramis:"Stizostedion lucioperca",
# names_to = "species",
# values_to = "numberPrey",
# values_drop_na = TRUE
# )
#
# glimpse(tidy)
# str(tidy)
#
# colourCount = length(unique(tidy$size))
# getPalette = colorRampPalette(brewer.pal(9, "OrRd")[2:9])
The data is now in long format (Just need to “uncount” the “number” column in the next step). Now we need to:
Add the rest of the species without size measurements
To do that, we need to select them from raw and pivot them to get the number too.
Bind row to tidy_size
Clean the size variable
Rejoice
# OK, kousek po kousku. Now we have to:
#
# 4) add the rest of the species without size measurements
# 4.1) To do that, we need to select them from raw and pivot them to get the number too.
#
# 5) bind row to tidy_size
# 6) clean the size variable
# 7) Rejoice
extra_sp <- raw %>%
dplyr::select(location, stretch, month, season, anguilla_anguilla, cyprinidae, astacus:serpentes) %>%
pivot_longer(
cols = c("anguilla_anguilla", "cyprinidae", astacus:serpentes),
names_to = "species",
values_to = "number",
values_drop_na = TRUE
)
tidy_db <- bind_rows(tidy_size, extra_sp) %>%
dplyr::filter(number > 0) %>%
dplyr::mutate(size = str_remove_all(size, "[*a-zA-Z_]")) %>%
dplyr::mutate(size = dplyr::recode(size,
"05" = "0-5 cm",
"510" = "5-10 cm",
"1015" = "10-15 cm",
"1520" = "15-20 cm",
"2025" = "20-25 cm",
"2530" = "25-30 cm",
"3035" = "30-35 cm",
"35-40" = "35-40 cm",
"4045" = "40-45 cm"
)) %>%
dplyr::mutate(size = fct_relevel(size, "5-10 cm", after = 1)) %>%
uncount(number) %>% # to get individual observations!!
dplyr::mutate(species = str_to_sentence(species)) %>%
dplyr::mutate(species = dplyr::recode(species,
"Astacus" = "Astacoidea",
"Anguilla_anguilla" = "Anguilla anguilla",
"Salmo trutta m. fario" = "Salmonids",
"Oncorhynchus mykiss" = "Salmonids",
"Cyprinidae" = "Unidentified Cyprinidae",
"Alburnoides bipunctatus" = "Alburnus alburnus",
"Gobio a romanogobio sp." = "Gobio a Romanogobio sp."
)) %>% # Trouts pooled into salmonids, Alburnoides into alburnus
dplyr::mutate(stretch = dplyr::recode(stretch,
"dolní" = "Lower",
"horní" = "Upper")) %>%
dplyr::mutate(species = as.factor(species)) %>%
dplyr::mutate(stretch = as.factor(stretch)) %>%
dplyr::mutate(species = fct_relevel(species, "Aves", after = Inf)) %>%
dplyr::mutate(species = fct_relevel(species, "Insecta", after = Inf)) %>%
dplyr::mutate(species = fct_relevel(species, "Mammalia", after = Inf)) %>%
dplyr::mutate(species = fct_relevel(species, "Anura", after = Inf)) %>%
dplyr::mutate(species = fct_relevel(species, "Serpentes", after = Inf)) %>%
dplyr::mutate(species = fct_relevel(species, "Astacoidea", after = Inf)) %>%
dplyr::mutate(season = dplyr::recode(season,
"winter" = "Winter",
"spring" = "Spring",
"summer" = "Summer",
"autumn" = "Autumn")) %>%
dplyr::mutate(season = as.factor(season)) %>%
dplyr::mutate(season = fct_relevel(season, "Spring", "Summer", "Autumn", "Winter" )) %>%
dplyr::mutate(location = as.factor(location)) %>%
# Divide streams into Upper and lower and removing variable stretch
dplyr::mutate(location = case_when(location == "Bílina" & stretch == "Upper" ~ "Horní Bílina",
location == "Bílina" & stretch == "Lower" ~ "Dolní Bílina",
location == "Chomutovka" & stretch == "Lower" ~ "Dolní Chomutovka",
location == "Chomutovka" & stretch == "Upper" ~ "Horní Chomutovka",
location == "Prisecnice" ~ "Přísečnice",
TRUE ~ "jezero Milada")) %>%
dplyr::mutate(location = as.factor(location)) %>%
dplyr::select(-stretch)
summary(tidy_db)
## location month season size
## Dolní Bílina :522 Length:1725 Spring:420 5-10 cm :693
## Dolní Chomutovka:149 Class :character Summer:399 10-15 cm:405
## Horní Bílina :129 Mode :character Autumn:555 15-20 cm: 75
## Horní Chomutovka:173 Winter:351 20-25 cm: 34
## jezero Milada :386 25-30 cm: 12
## Přísečnice :366 (Other) : 10
## NA's :496
## species
## Salmonids :310
## Gobio a Romanogobio sp.:255
## Perca fluviatilis :220
## Anura :219
## Astacoidea :154
## Unidentified Cyprinidae: 87
## (Other) :480
head(tidy_db)
## # A tibble: 6 x 5
## location month season size species
## <fct> <chr> <fct> <fct> <fct>
## 1 Dolní Bílina April Spring 10-15 cm Cyprinus carpio
## 2 Dolní Bílina April Spring 0-5 cm Gobio a Romanogobio sp.
## 3 Dolní Bílina April Spring 0-5 cm Gobio a Romanogobio sp.
## 4 Dolní Bílina April Spring 5-10 cm Gobio a Romanogobio sp.
## 5 Dolní Bílina April Spring 5-10 cm Gobio a Romanogobio sp.
## 6 Dolní Bílina April Spring 5-10 cm Gobio a Romanogobio sp.
write.csv2(tidy_db,"dataShiny/tidy_db", row.names = FALSE)
lumped_fish <- tidy_db %>%
dplyr::mutate(species = case_when(
species == "Aves" ~ "Aves",
species == "Insecta" ~ 'Insecta',
species == "Mammalia" ~ 'Mammalia',
species == "Anura" ~ 'Anura',
species == "Serpentes" ~ 'Serpentes',
species == "Astacoidea" ~ 'Astacoidea',
TRUE ~ 'Fish' ))
head(lumped_fish)
## # A tibble: 6 x 5
## location month season size species
## <fct> <chr> <fct> <fct> <chr>
## 1 Dolní Bílina April Spring 10-15 cm Fish
## 2 Dolní Bílina April Spring 0-5 cm Fish
## 3 Dolní Bílina April Spring 0-5 cm Fish
## 4 Dolní Bílina April Spring 5-10 cm Fish
## 5 Dolní Bílina April Spring 5-10 cm Fish
## 6 Dolní Bílina April Spring 5-10 cm Fish
write.csv2(lumped_fish,"dataShiny/lumped_fish", row.names = FALSE)
The category “Salmonids” includes Salmo trutta m.fario, Oncorhynchus mykiss and unidentified salmonids.
Number of individual prey found in spraints in each location
total_prey <- tidy_db %>%
dplyr::select(location, species) %>%
dplyr::count(species, location) %>%
pivot_wider(names_from = location, values_from = n ) %>%
replace(is.na(.), 0)
kable(total_prey, align = "lccrr") %>%
kableExtra::kable_styling()
| species | Dolní Bílina | Dolní Chomutovka | Horní Chomutovka | Horní Bílina | jezero Milada | Přísečnice |
|---|---|---|---|---|---|---|
| Abramis sp. | 3 | 0 | 0 | 0 | 0 | 0 |
| Alburnus alburnus | 8 | 0 | 0 | 0 | 0 | 0 |
| Anguilla anguilla | 3 | 0 | 0 | 0 | 0 | 0 |
| Barbatula barbatula | 2 | 18 | 1 | 0 | 0 | 0 |
| Barbus barbus | 5 | 0 | 0 | 0 | 0 | 0 |
| Carassius sp. | 24 | 5 | 1 | 6 | 0 | 0 |
| Ctenopharyngodon idella | 0 | 1 | 3 | 0 | 1 | 0 |
| Cyprinus carpio | 59 | 5 | 2 | 0 | 2 | 0 |
| Esox lucius | 0 | 1 | 0 | 0 | 0 | 0 |
| Gobio a Romanogobio sp. | 200 | 21 | 1 | 0 | 1 | 32 |
| Gymnocephalus cernua | 2 | 0 | 0 | 0 | 21 | 0 |
| Ictalurus nebulosus | 1 | 0 | 0 | 0 | 0 | 0 |
| Lepomis gibbosus | 5 | 0 | 0 | 0 | 8 | 0 |
| Lota lota | 0 | 0 | 0 | 0 | 0 | 1 |
| Perca fluviatilis | 5 | 9 | 1 | 1 | 200 | 4 |
| Phoxinus phoxinus | 0 | 0 | 0 | 0 | 0 | 9 |
| Pseudorasbora parva | 31 | 13 | 0 | 0 | 0 | 0 |
| Rutilus rutilus | 26 | 3 | 2 | 1 | 2 | 5 |
| Salmonids | 1 | 7 | 119 | 57 | 5 | 121 |
| Scardinius erythrophtalmus | 4 | 1 | 0 | 1 | 32 | 0 |
| Silurus glanis | 4 | 1 | 0 | 0 | 2 | 2 |
| Squalius cephalus | 32 | 28 | 0 | 0 | 1 | 2 |
| Tinca tinca | 11 | 1 | 0 | 0 | 45 | 0 |
| Unidentified Cyprinidae | 39 | 14 | 4 | 4 | 22 | 4 |
| Aves | 7 | 2 | 0 | 0 | 5 | 0 |
| Insecta | 1 | 0 | 0 | 1 | 5 | 2 |
| Mammalia | 0 | 3 | 0 | 0 | 0 | 1 |
| Anura | 45 | 14 | 38 | 39 | 13 | 70 |
| Serpentes | 3 | 2 | 0 | 0 | 1 | 0 |
| Astacoidea | 1 | 0 | 1 | 19 | 20 | 113 |
#Create custom palette
#
seed <- c("#ff0000", "#00ff00", "#0000ff")
species_v <- levels(tidy_db$species)
species_vector<- c(species_v, "Other")
# names(palette1) = species_vector
species_colors = setNames(object = createPalette(31, seed, prefix="mine"), nm = species_vector)
swatch(species_colors)
#print(species_colors)
(Lumping 5% less common)
tidy_db %>%
# group by location before lumping so that 0.05 applies to each separately
dplyr::group_by(location) %>%
mutate(species = fct_lump_prop(species,0.05)) %>%
ungroup() %>%
mutate(species = fct_reorder(species, desc(species))) %>%
dplyr::mutate(species = fct_relevel(species, "Astacoidea", "Anura", after = Inf)) %>%
dplyr::mutate(species = fct_relevel(species, "Other", after = Inf)) %>%
dplyr::mutate(location = fct_relevel(location, "jezero Milada", after = 0)) %>%
ggplot(aes(x = location, fill=species)) +
scale_fill_manual(values= species_colors) +
facet_wrap(. ~ season)+
geom_bar()+
theme_bw() +
scale_y_continuous("Identified prey") +
scale_x_discrete("") +
labs(fill = "Species") +
#theme(axis.text.x = element_text(angle = 90)) +
coord_flip() +
labs(title = "Krusne Hory: Most common prey by season") +
# scale_fill_brewer(palette = "Paired") +
# scale_fill_discrete(drop=FALSE) +
theme(axis.text.x = element_text(size = 10)) +
theme(axis.title.x = element_text(size = 15)) +
theme(axis.title.y = element_text(size = 15)) +
theme(plot.title = element_text(size = 15))+
guides(fill = guide_legend(reverse = TRUE))
tidy_db %>%
# group by stretch and location before lumping so that 0.05 applies to each stretch separatedly
dplyr::group_by(location) %>%
mutate(species = fct_lump_prop(species,0.05)) %>%
ungroup() %>%
mutate(species = fct_reorder(species, desc(species))) %>%
dplyr::mutate(species = fct_relevel(species, "Astacoidea", "Anura", after = Inf)) %>%
dplyr::mutate(species = fct_relevel(species, "Other", after = Inf)) %>%
dplyr::mutate(location = fct_relevel(location, "jezero Milada", after = 0)) %>%
ggplot(aes(x = location, fill=species)) +
scale_fill_manual(values= species_colors) +
#facet_grid(. ~ season)+
scale_y_continuous("Proportion of species", labels = scales::percent) +
scale_x_discrete("") +
geom_bar(position = "fill") +
labs(fill = "Species proportion") +
# theme(axis.text.x = element_text(angle = 90)) +
labs(title = "Krusne Hory: Most common prey, year round") +
coord_flip()+
guides(fill = guide_legend(reverse = TRUE))
lumped_fish %>%
mutate(species = fct_relevel(species,"Fish")) %>%
dplyr::mutate(location = fct_relevel(location, "jezero Milada", after = 0)) %>%
ggplot(aes(x = location, fill=species)) +
#facet_grid(. ~ season)+
scale_fill_discrete(drop=FALSE) +
scale_y_continuous("Proportion of species", labels = scales::percent) +
scale_x_discrete("") +
geom_bar(position = "fill") +
labs(fill = "Species proportion") +
scale_fill_brewer(palette = "Paired") +
# theme(axis.text.x = element_text(angle = 90)) +
labs(title = "Krusne Hory") +
coord_flip() +
guides(fill = guide_legend(reverse = TRUE))
lumped_fish %>%
mutate(species = fct_relevel(species,"Fish")) %>%
dplyr::mutate(location = fct_relevel(location, "jezero Milada", after = 0)) %>%
ggplot(aes(x = location, fill=species)) +
facet_wrap(. ~ season)+
scale_fill_discrete(drop=FALSE) +
scale_y_continuous("Proportion of species", labels = scales::percent) +
scale_x_discrete("") +
geom_bar(position = "fill") +
labs(fill = "Species proportion") +
scale_fill_brewer(palette = "Paired") +
# theme(axis.text.x = element_text(angle = 90)) +
labs(title = "Krusne Hory") +
coord_flip()+
guides(fill = guide_legend(reverse = TRUE))
tidy_db %>%
filter(location == "Horní Bílina") %>%
dplyr::filter(season != "Winter") %>%
mutate(species = fct_infreq(species)) %>%
ggplot(aes(x = species, group = location, fill=species)) +
geom_bar(aes(y = ..prop.., fill = factor(..x..)), stat = "count", show.legend = FALSE) +
#scale_fill_manual(values = species_colors) +
geom_text(aes(
label = scales::percent(..prop.., accuracy = 2L),
y = ..prop..
), stat = "count", vjust = -0.1, hjust = -0.1, size = 3) +
labs(y = "", x = "") +
facet_wrap(~season) +
coord_flip() +
labs(title = "Horní Bílina: Otter diet by season") +
scale_y_continuous(labels = scales::percent_format(accuracy = 1L), limits = c(0, 0.6))
dBilina <- tidy_db %>%
filter(location == "Dolní Bílina")
dBilina %>%
#mutate(species = fct_lump_prop(species,0.05)) %>%
# dplyr::filter(season != "Winter") %>%
#dplyr::mutate(species = fct_relevel(species, "Other", after = Inf)) %>%
mutate(species = fct_infreq(species)) %>%
ggplot( aes(x= species, group = location), show.legend = FALSE) +
geom_bar(aes(y = ..prop.., fill = factor(..x..)), stat="count", show.legend = FALSE) +
geom_text(aes( label = scales::percent(..prop.., accuracy= 0.1),
y= ..prop.. ), stat= "count", vjust = 0, hjust = -0.1, size=3) +
labs(y = "", x ="") +
facet_wrap(~ season) +
coord_flip() +
labs(title = "Dolní Bílina: Otter diet by season") +
scale_y_continuous(labels = scales::percent_format(), limits = c(0, 0.65))
dBilina <- tidy_db %>%
filter(location == "Dolní Bílina")
dBilina %>%
mutate(species = fct_lump_prop(species,0.05)) %>%
# dplyr::filter(season != "Winter") %>%
#dplyr::mutate(species = fct_relevel(species, "Other", after = Inf)) %>%
mutate(species = fct_infreq(species)) %>%
ggplot( aes(x= species, group = location), show.legend = FALSE) +
geom_bar(aes(y = ..prop.., fill = factor(..x..)), stat="count", show.legend = FALSE) +
geom_text(aes( label = scales::percent(..prop..,accuracy = 2L),
y= ..prop.. ), stat= "count", vjust = 0, hjust = -0.1, size=3) +
labs(y = "", x ="") +
facet_wrap(~ season) +
coord_flip() +
labs(title = "Dolní Bílina: Otter diet by season") +
scale_y_continuous(labels = scales::percent_format(accuracy = 1L), limits = c(0, 0.6))
Water reservoir for human consumption.
pris <- tidy_db %>%
filter(location == "Přísečnice")
pris %>%
#mutate(species = fct_lump_prop(species,0.05)) %>%
dplyr::filter(season != "Winter") %>%
#dplyr::mutate(species = fct_relevel(species, "Other", after = Inf)) %>%
mutate(species = fct_infreq(species)) %>%
ggplot( aes(x= species, group = location), show.legend = FALSE) +
geom_bar(aes(y = ..prop.., fill = factor(..x..)), stat="count", show.legend = FALSE) +
geom_text(aes( label = scales::percent(..prop..,accuracy = 1L),
y= ..prop.. ), stat= "count", vjust = 0, hjust = -0.1, size=3) +
labs(y = "", x ="") +
facet_wrap(~ season) +
coord_flip() +
labs(title = "Přísečnice: Otter diet by season") +
scale_y_continuous(labels = scales::percent_format(accuracy = 1L), limits = c(0, 0.6))
jez <- tidy_db %>%
filter(location == "jezero Milada")
jez %>%
#mutate(species = fct_lump_prop(species,0.05)) %>%
#dplyr::filter(season != "Winter") %>%
#dplyr::mutate(species = fct_relevel(species, "Other", after = Inf)) %>%
mutate(species = fct_infreq(species)) %>%
ggplot( aes(x= species, group = location), show.legend = FALSE) +
geom_bar(aes(y = ..prop.., fill = factor(..x..)), stat="count", show.legend = FALSE) +
geom_text(aes( label = scales::percent(..prop..,accuracy = 0.1),
y= ..prop.. ), stat= "count", vjust = 0, hjust = -0.1, size= 3) +
labs(y = "", x ="") +
facet_wrap(~ season) +
coord_flip() +
labs(title = "Jezero Milada: Otter diet by season") +
scale_y_continuous(labels = scales::percent_format(accuracy = 1L), limits = c(0,1))
jez <- tidy_db %>%
filter(location == "jezero Milada")
jez %>%
mutate(species = fct_lump_prop(species,0.05)) %>%
#dplyr::filter(season != "Winter") %>%
#dplyr::mutate(species = fct_relevel(species, "Other", after = Inf)) %>%
mutate(species = fct_infreq(species)) %>%
ggplot( aes(x= species, group = location), show.legend = FALSE) +
geom_bar(aes(y = ..prop.., fill = factor(..x..)), stat="count", show.legend = FALSE) +
geom_text(aes( label = scales::percent(..prop..,accuracy = 2L),
y= ..prop.. ), stat= "count", vjust = 0, hjust = -0.1, size= 3) +
labs(y = "", x ="") +
facet_wrap(~ season) +
coord_flip() +
labs(title = "Jezero Milada: Otter diet by season") +
scale_y_continuous(labels = scales::percent_format(accuracy = 1L), limits = c(0,1))
dCho <- tidy_db %>%
filter(location == "Dolní Chomutovka")
dCho %>%
#mutate(species = fct_lump_prop(species,0.05)) %>%
#dplyr::filter(season != "Winter") %>%
#dplyr::mutate(species = fct_relevel(species, "Other", after = Inf)) %>%
mutate(species = fct_infreq(species)) %>%
ggplot( aes(x= species, group = location), show.legend = FALSE) +
geom_bar(aes(y = ..prop.., fill = factor(..x..)), stat="count", show.legend = FALSE) +
geom_text(aes( label = scales::percent(..prop..,accuracy = 2L),
y= ..prop.. ), stat= "count", vjust = 0, hjust = -0.1,size=2.5) +
labs(y = "", x ="") +
facet_wrap(~ season) +
coord_flip() +
labs(title = "Dolní Chomutovka: Otter diet by season") +
scale_y_continuous(labels = scales::percent_format(accuracy = 1L), limits = c(0,0.6))
hCho <- tidy_db %>%
filter(location == "Horní Chomutovka")
hCho %>%
#mutate(species = fct_lump_prop(species,0.05)) %>%
dplyr::filter(season != "Summer") %>%
#dplyr::mutate(species = fct_relevel(species, "Other", after = Inf)) %>%
mutate(species = fct_infreq(species)) %>%
ggplot( aes(x= species, group = location), show.legend = FALSE) +
geom_bar(aes(y = ..prop.., fill = factor(..x..)), stat="count", show.legend = FALSE) +
geom_text(aes( label = scales::percent(..prop..,accuracy = 2L),
y= ..prop.. ), stat= "count", vjust = -0, hjust = -0.1, size =3) +
labs(y = "", x ="") +
facet_wrap(~ season) +
coord_flip() +
labs(title = "Horní Chomutovka: Otter diet by season") +
scale_y_continuous(labels = scales::percent_format(accuracy = 1L), limits = c(0,1))
Plot all together just to see if the data looks right.
lumped_fish %>%
drop_na(size) %>%
dplyr::filter(species == "Fish") %>%
ggplot(aes(x = location, fill = size)) +
#facet_grid(. ~ location)+
geom_bar( position = "dodge")+
scale_y_continuous("") +
scale_x_discrete("") +
labs(fill = "Size") +
#theme(axis.text.x = element_text(angle = 90)) +
# coord_flip() +
labs(title = "Krusne Hory: Size distribution") +
scale_fill_brewer(palette = "Paired") +
scale_fill_discrete(drop=TRUE) +
theme(axis.text.x = element_text(size = 10)) +
theme(axis.title.x = element_text(size = 15)) +
theme(axis.title.y = element_text(size = 15)) +
theme(plot.title = element_text(size = 15))
theme(axis.title.y = element_text(size = 15)) +
theme(plot.title = element_text(size = 15))
## List of 2
## $ axis.title.y:List of 11
## ..$ family : NULL
## ..$ face : NULL
## ..$ colour : NULL
## ..$ size : num 15
## ..$ hjust : NULL
## ..$ vjust : NULL
## ..$ angle : NULL
## ..$ lineheight : NULL
## ..$ margin : NULL
## ..$ debug : NULL
## ..$ inherit.blank: logi FALSE
## ..- attr(*, "class")= chr [1:2] "element_text" "element"
## $ plot.title :List of 11
## ..$ family : NULL
## ..$ face : NULL
## ..$ colour : NULL
## ..$ size : num 15
## ..$ hjust : NULL
## ..$ vjust : NULL
## ..$ angle : NULL
## ..$ lineheight : NULL
## ..$ margin : NULL
## ..$ debug : NULL
## ..$ inherit.blank: logi FALSE
## ..- attr(*, "class")= chr [1:2] "element_text" "element"
## - attr(*, "class")= chr [1:2] "theme" "gg"
## - attr(*, "complete")= logi FALSE
## - attr(*, "validate")= logi TRUE
tidy_db %>%
dplyr::filter(species == "Salmonids") %>%
ggplot(aes(x = species, fill = size)) +
facet_grid(. ~ location)+
geom_bar( position = "dodge")+
scale_y_continuous("") +
scale_x_discrete("", labels=NULL) +
labs(fill = "Size") +
#theme(axis.text.x = element_text(angle = 90)) +
# coord_flip() +
labs(title = "Krusne Hory: Size distribution of salmonids") +
scale_fill_brewer(palette = "Paired") +
scale_fill_discrete(drop=FALSE) +
theme(axis.text.x = element_text(size = 10)) +
theme(axis.title.x = NULL) +
theme(axis.title.y = element_text(size = 15)) +
theme(plot.title = element_text(size = 15))