This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

raw data Victor

## Warning: Paket 'DT' wurde unter R Version 4.2.3 erstellt
## Warning: Paket 'ggplot2' wurde unter R Version 4.2.3 erstellt
## Warning: Paket 'tibble' wurde unter R Version 4.2.3 erstellt
## Warning: Paket 'dplyr' wurde unter R Version 4.2.3 erstellt
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
## [1] "C:/Users/victors94/Documents/R/climbee_analysis"
## New names:
## • `` -> `...39`
library(tidyverse)
temp <- a0 %>% 
  separate(`Taxon-ID`, c("Gattung", "Art", "x1", "x2"), remove = F, sep = " ") %>%
  dplyr::select(-x1, -x2) %>% 
  filter(Gattung == "Andrena") %>% 
  mutate(x = 1) %>% 
  group_by(Gemeinde, `Taxon-ID`) %>% 
  dplyr::summarise(Anzahl = sum(x)) %>% 
  group_by(Gemeinde) %>% 
  mutate(Sum_Sample = sum(Anzahl),
         Sum_Arten = n_distinct(`Taxon-ID`)) %>% 
  mutate_if(is.character, as.factor) %>% 
 # arrange(Sum_Sample) %>% 
  mutate(Gemeinde = as.factor(Gemeinde))

temp %>% 
  datatable(extensions = 'Buttons',
            options = list(dom = 'Blfrtip',
                           buttons = c('copy', 'csv', 'excel', 'pdf', 'print'),
                           lengthMenu = list(c(10,25,50,-1),
                                      c(10,25,50,"All"))))
str(temp)
## gropd_df [133 × 5] (S3: grouped_df/tbl_df/tbl/data.frame)
##  $ Gemeinde  : Factor w/ 10 levels "Apetlon","Gramatneusiedl",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ Taxon-ID  : Factor w/ 51 levels "Andrena bimaculata (Kirby, 1802)",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ Anzahl    : num [1:133] 3 13 2 2 3 7 8 2 1 7 ...
##  $ Sum_Sample: num [1:133] 58 58 58 58 58 58 58 58 58 58 ...
##  $ Sum_Arten : int [1:133] 15 15 15 15 15 15 15 15 15 15 ...
##  - attr(*, "groups")= tibble [10 × 2] (S3: tbl_df/tbl/data.frame)
##   ..$ Gemeinde: Factor w/ 10 levels "Apetlon","Gramatneusiedl",..: 1 2 3 4 5 6 7 8 9 10
##   ..$ .rows   : list<int> [1:10] 
##   .. ..$ : int [1:15] 1 2 3 4 5 6 7 8 9 10 ...
##   .. ..$ : int [1:7] 16 17 18 19 20 21 22
##   .. ..$ : int [1:15] 23 24 25 26 27 28 29 30 31 32 ...
##   .. ..$ : int [1:15] 38 39 40 41 42 43 44 45 46 47 ...
##   .. ..$ : int [1:11] 53 54 55 56 57 58 59 60 61 62 ...
##   .. ..$ : int [1:19] 64 65 66 67 68 69 70 71 72 73 ...
##   .. ..$ : int [1:14] 83 84 85 86 87 88 89 90 91 92 ...
##   .. ..$ : int [1:10] 97 98 99 100 101 102 103 104 105 106
##   .. ..$ : int [1:15] 107 108 109 110 111 112 113 114 115 116 ...
##   .. ..$ : int [1:12] 122 123 124 125 126 127 128 129 130 131 ...
##   .. ..@ ptype: int(0) 
##   ..- attr(*, ".drop")= logi TRUE
library(ggsci)
library(viridis)

# Create the plot
temp %>% 
  mutate(y = 1) %>% 
ggplot(aes(x = Gemeinde, y = y, fill = as.factor(Sum_Sample))) +
  geom_bar(stat = "identity") +
  labs(x = "Sampling Locations (Gemeinde)", y = "Number of Andrena Species", fill = "Anzahl Hackserl") +
  ggtitle("Number of Andrena Species by Sampling Location") +
  theme_minimal() +
  scale_fill_viridis_d()+
  theme(axis.text.x = element_text(angle = 45, hjust = 1))