Ifeanyi commited on
Commit
8fe5327
·
verified ·
1 Parent(s): 5c9a01f

Upload 4 files

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. Map.R +84 -0
  3. Plot.R +30 -0
  4. Table.R +55 -0
  5. poland.csv +3 -0
.gitattributes CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ poland.csv filter=lfs diff=lfs merge=lfs -text
Map.R ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import specific functions from relevant libraries
2
+ box::use(leaflet[
3
+ leaflet,
4
+ providers,
5
+ addTiles,
6
+ addProviderTiles,
7
+ addPolygons,
8
+ addLegend,
9
+ addControl,
10
+ setView,
11
+ addCircleMarkers,
12
+ colorBin,
13
+ colorNumeric,
14
+ markerClusterOptions,
15
+ labelOptions
16
+ ])
17
+ box::use(leaflet.extras[
18
+ addFullscreenControl,
19
+ addSearchFeatures,
20
+ searchFeaturesOptions
21
+ ])
22
+ box::use(dplyr[filter])
23
+ box::use(viridis)
24
+
25
+
26
+ #* @param df data frame containing map coordinates
27
+ #* @param vernacular the vernacular names of the animals
28
+ #* @param locality regions in Poland
29
+ # write map function
30
+ mapData <- function(df, vernacular) {
31
+ # set default values if arguments are NULL or empty
32
+ if (is.null(vernacular)) {
33
+ vernacular <- "Mandarin Duck"
34
+ } else {
35
+ vernacular
36
+ }
37
+
38
+ # filter the data based on vernacular and locality
39
+ filtered_df <- df |>
40
+ filter(vernacularName == vernacular)
41
+
42
+
43
+ # ensure there is data to display
44
+ if (nrow(filtered_df) == 0) {
45
+ leaflet() |>
46
+ addTiles() |>
47
+ addPopups(lng = 0, lat = 0, popup = "No data available for the selected filters")
48
+ }
49
+
50
+
51
+ # create a color palette for markers
52
+ pal <- colorNumeric(palette = "Paired", domain = filtered_df$individualCount)
53
+
54
+ # create the tooltip labels
55
+ labels <- paste0(
56
+ "<b>Vernacular Name: </b>", filtered_df$vernacularName, "<br>",
57
+ "<b>Individual Count: </b>", filtered_df$individualCount, "<br>",
58
+ "<b>Locality: </b>", filtered_df$locality
59
+ ) |> lapply(htmltools::HTML)
60
+
61
+ # create the map
62
+ leaflet(filtered_df) |>
63
+ addTiles() |>
64
+ addProviderTiles(providers$CartoDB.Positron) |>
65
+ addCircleMarkers(
66
+ lng = ~longitudeDecimal,
67
+ lat = ~latitudeDecimal,
68
+ color = ~ pal(individualCount),
69
+ fillColor = ~ pal(individualCount),
70
+ fillOpacity = 0.7,
71
+ label = labels,
72
+ labelOptions = labelOptions(
73
+ style = list("font-weight" = "normal", padding = "3px 8px"),
74
+ textsize = "15px",
75
+ direction = "auto"
76
+ )
77
+ ) |>
78
+ addLegend(
79
+ pal = pal,
80
+ values = ~individualCount,
81
+ title = "Individual Count",
82
+ position = "bottomright"
83
+ )
84
+ }
Plot.R ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ box::use(highcharter[highchart,
2
+ hcaes,
3
+ hc_title,
4
+ hc_xAxis,
5
+ hc_yAxis,
6
+ hc_tooltip])
7
+
8
+ box::use(dplyr[filter])
9
+
10
+ #* @param df data frame containing the data
11
+ #* @param vernacular the vernacular names of the animals
12
+ plotData <- function(df,vernacular,locality) {
13
+
14
+ df |>
15
+ filter(vernacularName == vernacular,locality == locality) |>
16
+ hchart(
17
+ type = "scatter",
18
+ hcaes(x = eventDate,
19
+ y = individualCount)) |>
20
+ hc_title(text = "Biodiversity in Poland") |>
21
+ hc_xAxis(title = list(text = "Event Date")) |>
22
+ hc_yAxis(title = list(text = "Individual Count")) |>
23
+ hc_tooltip(
24
+ pointFormat = 'Date: {point.x:%Y-%m-%d}<br>Individual Count: {point.y:.2f}'
25
+ )
26
+
27
+ }
28
+
29
+ # plotData(bio_pol,
30
+ # vernacular = "Mandarin Duck")
Table.R ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ library(reactablefmtr)
2
+
3
+ # import specific functions from relevant libraries
4
+ box::use(reactable[reactable, colDef])
5
+ box::use(dplyr[filter])
6
+
7
+
8
+ #* @param df the data frame containing the data
9
+ #* @param vernacular the vernacular names of the animals
10
+ #* @param locality regions in Poland
11
+ tableFunction <- function(df, vernacular) {
12
+ # set default values if arguments are NULL or empty
13
+ if (is.null(vernacular) || vernacular == "") {
14
+ vernacular <- "Mandarin Duck"
15
+ } else {
16
+ vernacular
17
+ }
18
+
19
+ # filter the data based on vernacular and locality
20
+ filtered_df <- df |>
21
+ filter(vernacularName == vernacular)
22
+
23
+
24
+ # ensure there is data to display
25
+ if (nrow(filtered_df) == 0) {
26
+ reactable(data.frame(
27
+ Message = "No data available for the selected filters"
28
+ ))
29
+ }
30
+
31
+ # return table
32
+ reactable(
33
+ filtered_df,
34
+ filterable = TRUE,
35
+ searchable = TRUE,
36
+ striped = TRUE,
37
+ highlight = TRUE,
38
+ bordered = TRUE,
39
+ compact = TRUE,
40
+ defaultPageSize = 10,
41
+ columns = list(
42
+ vernacularName = colDef(name = "Common Name"),
43
+ longitudeDecimal = colDef(name = "Longitude"),
44
+ latitudeDecimal = colDef(name = "Latitude"),
45
+ individualCount = colDef(name = "Count"),
46
+ eventDate = colDef(name = "Date"),
47
+ locality = colDef(name = "Location")
48
+ ),
49
+ theme = reactableTheme(
50
+ highlightColor = "#627cfc",
51
+ borderColor = "#1239fe",
52
+ borderWidth = 2
53
+ )
54
+ )
55
+ }
poland.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:812db5fdd7af52b5d8593cb8fb41ae9f419144e5b56683a3215b24f138eee1b9
3
+ size 21759875