Skip to content

Commit

Permalink
Merge pull request #33 from joyliujoyliu/main
Browse files Browse the repository at this point in the history
mapview to leaflet
  • Loading branch information
joyliujoyliu authored Jul 2, 2024
2 parents 268ce35 + 690c629 commit 44285c5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 12 deletions.
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ Imports:
quarto,
readxl,
rmarkdown,
utils
utils,
leaflet,
leaflegend,
tidyr
Suggests:
curl,
knitr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(deployment_gantt)
export(leaflet_graph)
export(make_receiver_push_summary)
export(make_tag_push_summary)
export(match_map)
Expand Down
43 changes: 43 additions & 0 deletions R/leaflet_graph.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#' Plot the leaflet graphs for detection and individual
#' @param station_spatial is created by prep_station_spatial,which is a spatial object with the geometry
#' @export

leaflet_graph <- function(station_spatial) {
geometry<- NULL
df <- station_spatial |> tidyr::extract(geometry, c('lon', 'lat'), '\\((.*), (.*)\\)', convert = TRUE)
numPal <- leaflet::colorNumeric('viridis', df $Detections)
leaflet::leaflet(data = df) |>
leaflet::addTiles() |>
leaflet::addCircleMarkers( lat = ~lat, lng = ~lon,
color= ~numPal(Detections), fillColor = ~numPal(Detections),fillOpacity = 0.7,
popup = paste("Station ", df$station , "<br>",
"PI:", df$PI, "<br>",
"Detections:", df$Detections, "<br>",
"detectedby:", df$detectedby, "<br>",
"Individuals:", df$Individuals),
radius = ~Individuals) |>

leaflegend::addLegendSize(
values = df $Individuals,
baseSize = 1,
color = 'black',
title = 'Individual',
shape = 'circle',
orientation = 'horizontal',
opacity = .5,
fillOpacity = 0,
breaks = 5,
position = 'bottomright') |>
leaflegend::addLegendNumeric(
pal = numPal,
title = 'Matched Detection',
shape = 'stadium',
values = df $Detections,
fillOpacity = .5,
decreasing = TRUE,
position = 'bottomright')



}

17 changes: 6 additions & 11 deletions inst/qmd_template/make_tag_push_summary.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ knitr::opts_chunk$set(
```{r}
#| label: packages
#| message: false
library(otndo)
library(data.table)
library(mapview)
library(otndo)
library(reactable)
```

Expand Down Expand Up @@ -226,18 +224,15 @@ reactable(new_station_summary)

```{r}
#| label: new-detection-map-leaflet
#| fig-cap: Figure 7. Number of newly-added detections per receiver. Points represent receiver locations, while size and color reflect the number of detections at that location.
#| fig-cap: Figure 7. Number of newly-added detections per receiver. Points represent receiver locations, where color reflects the number of detections and size reflects the number of fish at that location.
#| eval: !expr "nrow(new_matches) > 0"
new_station_spatial <- prep_station_spatial(new_matches, type = "tag")
mapview::mapview(new_station_spatial,
zcol = "Detections",
cex = "Individuals",
layer.name = "Matched detections"
)
leaflet_graph(station_spatial)
```




```{r results='asis', echo=FALSE}
if (is.null(params$since)) {
cat("-->")
Expand Down
14 changes: 14 additions & 0 deletions man/leaflet_graph.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 44285c5

Please sign in to comment.