Commit 15a47d97 authored by Alex Nunes's avatar Alex Nunes
Browse files

Minor changes to the network analysis

parent 1ebc2fc2
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
%% Cell type:code id: tags:

``` R
library(dplyr)
library(glatos)
library(stringr)
library(plotly)
```

%% Cell type:code id: tags:

``` R
det_file <- system.file("extdata", "walleye_detections.csv",
                         package = "glatos")
detections <- read_glatos_detections(det_file)

detections <- glatos::false_detections(detections, tf = 3600)
filtered_detections <- detections %>% filter(passed_filter != FALSE)
detection_events <- glatos::detection_events(filtered_detections, location_col = 'station')
```

%% Cell type:code id: tags:

``` R
detection_events %>%
arrange(first_detection) %>%
group_by(individual) %>%
mutate(to = lead(location)) %>%
mutate(to_latitude = lead(mean_latitude)) %>%
mutate(to_longitude = lead(mean_longitude)) %>%
group_by(location, to) %>%
summarise(moves = n(),
          latitude = mean(mean_latitude),
          longitude=mean(mean_longitude),
          to_latitude=mean(to_latitude),
          to_longitude=mean(to_longitude)
          to_longitude=mean(to_longitude),
          res_time_seconds = mean(res_time_sec)
         ) %>%
rename(from=location) %>%
na.omit() -> network_analysis_data

receivers <- network_analysis_data %>%
                group_by(from) %>%
                summarise(
                  latitude = mean(latitude),
                  longitude = mean(longitude),
                    n = sum(moves)
                    visits = sum(moves),
                    res_time_seconds = mean(res_time_seconds)
                 )


```

%% Cell type:code id: tags:

``` R
geo <- list(
    projection = list(type = 'azimuthal equal area'),
    showland = TRUE,
    showland = TRUE,
    landcolor = toRGB("gray95"),
    countrycolor = toRGB("gray80"),
    showlakes =TRUE,
    lakecolor = toRGB("#A0AAB4"),
    resolution = 50,
    center = list(lat = ~median(latitude),
                lon = ~median(longitude)),
    lonaxis = list(range=c(~min(longitude)-1, ~max(longitude)+1)),
    lataxis = list(range=c(~min(latitude)-1, ~max(latitude)+1))
)

network <- network_analysis_data %>%
    plot_geo(height=800) %>%
    add_segments(
        x = ~longitude, xend = ~to_longitude,
        y = ~latitude, yend = ~to_latitude,
        alpha = 0.4, size = I(1.5), hoverinfo = "none", color=I("red")
      ) %>%
      add_markers(
        data=receivers,
        x = ~longitude, y = ~latitude, text = ~paste(from, ":", n),
        size = ~n, hoverinfo = "text", alpha = 0.9, color=~n
        x = ~longitude, y = ~latitude, text = ~paste(from, ":", visits, ' visits & ', res_time_seconds, ' seconds of residence time on average'),
        size = ~res_time_seconds, hoverinfo = "text", alpha = 0.5, color=~visits
      ) %>%
      layout(
        title = 'Walleye Salmon Network Plot',
        geo = geo, showlegend = FALSE
      )
```

%% Cell type:code id: tags:

``` R
embed_notebook(network)
```

%% Cell type:code id: tags:

``` R
library(cowsay)
cowsay::say("Any questions?",by="shark",)
```

%% Cell type:code id: tags:

``` R
```