-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkarta.Rmd
160 lines (128 loc) · 4.59 KB
/
karta.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
---
title: "Björninventering Dalarnas, Gävleborgs och Värmlands län, 21 augusti-31 oktober 2022"
output:
flexdashboard::flex_dashboard:
theme: readable
logo: naturhistoriska-riksmuseet.png
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(readxl)
library(dplyr)
library(leaflet)
library(ggplot2)
library(wesanderson)
library(RColorBrewer)
library(leaflet.extras)
library(lubridate)
library(rgdal)
library(sf)
source("utils.r")
# Make colors accessible c(gray, orange, green)
#plotcol <- c("#bcbcbc",
# "#f8bc05",
# "#1ace00")
plotcol <- c("gray",
"orange",
"green")
lan <- c("Dalarnas län (S)",
"Gävleborgs län (S)",
"Värmlands län (S)",
"Stockholms län (S)",
"Uppsala län (S)",
"Örebro län (S)",
"Västmanlands län (S)")
# DNA <- read_excel("Data/Progress.xlsx")
# names(DNA) <- c("Position","TubeID", "RackID", "Streckkod")
DNA <- ExcelToDF(dir = "Data", pattern = "*_SEP.xlsx")
colnames(DNA) <- c("Position", "RackID", "TubeID", "Streckkod")
bear <- read_excel("Data/rovbasedata.xlsx")
colnames(bear) <- c("Streckkod", "Art", "Provtyp", "Lat", "Long", "Datum", "Kommunnummer", "Kommun", "Lansnummer", "Lan")
bear <- bear[bear$Lan %in% lan,]
DNA <- DNA[!duplicated(DNA$Streckkod),]
bearmap <- base::merge(bear, DNA, by = "Streckkod", all.x = TRUE)
bearmap$RackID[is.na(bearmap$RackID)] <- 0
bearmap$RackID[bearmap$RackID>1] <- 1
bearmap$Genotyp <- 0
gt <- ExcelToDF(dir = "Data/Analysed/", pattern = "*_SEP.xlsx")
gtu <- unique(gt$SEP)
bearmap$Genotyp <- bearmap$Streckkod%in%gtu
bearmap$Genotyp <- ifelse(bearmap$Genotyp, yes = 1, no = 0)
bearmap <- gps_convert(data = bearmap, latitude = "Lat", longitude = "Long")
bearmap$Datum <- as.Date(bearmap$Datum)
bearmap$code <- ifelse(bearmap$RackID + bearmap$Genotyp == 0,
yes = "1. Registrerad",
ifelse(bearmap$RackID + bearmap$Genotyp > 1.9,
yes = "3. Prov analyserat",
no = "2. DNA extraherat"))
bearmap$code <- factor(bearmap$code, levels = c("1. Registrerad",
"2. DNA extraherat",
"3. Prov analyserat"))
#bearmap[order(as.character(bearmap$code), decreasing = FALSE),]
```
```{r}
getColor <- function() {
sapply(bearmap$code, function(code) {
if(code == "1. Registrerad") {
plotcol[1]
} else if(code == "2. DNA extraherat") {
plotcol[2]
} else {
plotcol[3]
} })
}
icons <- awesomeIcons(
icon = 'ios-close',
iconColor = 'black',
library = 'ion',
markerColor = getColor()
)
```
Column {data-width=650}
-----------------------------------------------------------------------
### Spillningsprover som inkommit till Naturhistoriska riksmuseet (NRM)
```{r}
# Mapping colors to the icons is done by eyeballing
pal <- colorFactor(plotcol , domain = bearmap$code, ordered = FALSE)
leaflet(bearmap) %>%
addTiles(group = "OSM") %>%
addProviderTiles(providers$OpenStreetMap,
options = providerTileOptions(noWrap = TRUE)) %>%
addAwesomeMarkers(icon=icons, label=~as.character(Streckkod), group = "marker", clusterOptions = markerClusterOptions(), options = ) %>%
addLegend( pal=pal, values = ~levels(code), opacity=0.8, title = "Provstatus", position = "bottomleft") %>%
addSearchFeatures('marker', options = searchFeaturesOptions(zoom = 15,
openPopup = TRUE,
firstTipSubmit = TRUE,
autoCollapse = TRUE,
hideMarkerOnCollapse = FALSE))
# hideGroup("marker")
```
Column {data-width=350}
-----------------------------------------------------------------------
### Antal insamlade prover per dag sedan inventeringsstarten den 21 Augusti
```{r}
ggplot(as.data.frame(bearmap)) + aes(x = Datum) + geom_bar(alpha=0.8) + scale_y_continuous(name = "Insamlade prover per dag")
```
### inkomna prover fram till `r Sys.Date()`
```{r}
Bearsamples <- length(bearmap$code)
valueBox(Bearsamples,
icon = "fa-clipboard-check",
color = plotcol[1])
```
### DNA extraherat fram till `r Sys.Date()`
```{r}
dnaextract <- sum(bearmap$code == "2. DNA extraherat" | bearmap$code == "3. Prov analyserat")
valueBox(dnaextract,
icon = "fa-dna",
color = plotcol[2])
```
### Färdiganalyserade prover `r Sys.Date()`
```{r}
genotyped <- sum(bearmap$code == "3. Prov analyserat")
valueBox(genotyped,
icon = "fa-paw",
color = plotcol[3])
```