Column1

Tablas de observaciones por:

Unidades regionales de NeoMapas

Unidades regionales Observaciones Registros
sin información 4 6
NM92 (d10) 3 13
celda d13 3 4
NM09 (d19) 2 5
NM19 (i05) 2 2
NM26 (h04) 2 8
celda h05 2 3
NM02 (b07) 1 1
NM03 (d06) 1 2
NM05 (d02) 1 2
NM18 (i05) 1 1
NM19 (i06) 1 1
NM24 (i22) 1 3
NM27 (g05) 1 1
NM27 (g06) 1 1
NM50 (d10) 1 6
celda a07 1 5
celda b06 1 1
celda b09 1 1
celda c11 1 3

Especies

Especies Observaciones Registros
Avicularia avicularia 2 2
Catasticta 2 2
Acanthops 1 1
Accipitridae 1 1
Adelpha alala 1 1
Amazilia 1 1
Anartia amathea 1 1
Anolis onca 1 1
Anthurium 1 1
Apoica gelida 1 1
Arecaceae 1 1
Balaenoptera acutorostrata 1 1
Burnsius 1 1
Capra hircus 1 1
Cardinalis phoeniceus 1 1
Catasticta hebra 1 1
Cerdocyon thous 1 1
Chalybura buffonii 1 1
Charidotis abrupta 1 1
Cnemidophorus splendidus 1 1

Lugares

Lugar Observaciones Registros
Ezequiel Zamora, 5210, Barinas, Venezuela 4 4
Cruz Salmeron Acosta, 6102, Sucre, Venezuela 3 4
Hacienda Guáquira, Final Calle, La Marroquina, La Marroquine 3201, Yaracuy, Venezuela 3 8
Campo Elías, Mérida, Venezuela 2 2
Municipio Los Salias, 1204, Miranda, Venezuela 2 2
2061, Falcón, Venezuela 1 3
86895 Tacotalpa, Tab., Mexico 1 2
92Q7+W9P, Parroquia Macarao 1204, Miranda, Venezuela 1 1
Andres Bello, 5102, Mérida, Venezuela 1 1
Araya 6102, Sucre, Venezuela 1 3
Aricagua, 5119, Mérida, Venezuela 1 1
Barrio de la Base Naval, Puerto Cabello 2050, Carabobo, Venezuela 1 1
Buchivacoa, Falcón, Venezuela 1 1
Camatagua 2335, Aragua, Venezuela 1 3
Campo Elias, Mérida, Venezuela 1 7
Caracciolo Parra Olmedo, 5146, Mérida, Venezuela 1 1
Carirubana, Falcón, Venezuela 1 1
Cocorote, 3208, Yaracuy, Venezuela 1 6
Gamboa Rainforest Reserve, Goethals Blvd, Gamboa, Provincia de Colón, Panama 1 2
H7QP+7MW, Maracaibo 4004, Zulia, Venezuela 1 1

Column2

Mapa

Phylum

Observaciones por año

Calendario de observaciones

Column3

Números

---
title: "Observaciones en iNaturalist"
output: 
  flexdashboard::flex_dashboard:
    theme: 
      version: 4
      bootswatch: superhero
    social: menu
    source: embed
    logo: NeoMapas_logo_100x.gif
    navbar:
      - { title: "Volver al inicio", href: "https://neomapas.github.io", align: left }
editor_options: 
  chunk_output_type: console
---

```{r setup, include=FALSE}
library(flexdashboard)
library(leaflet)
library(ggplot2)
library(plotly)
library(spocc)
library(rinat)
#library(mapr)
library(sf)
library(tmap)
library(lubridate)
library(dplyr)
library(stringr)

library(RColorBrewer)
palette(brewer.pal(8, "Set2"))

```

```{r dataread, message=FALSE, warning=FALSE, include=FALSE}

here::i_am("index.Rmd")

CNEB <- read_sf(here::here("data", "VBG.gpkg")) 

JR_obs <- readRDS(here::here("data","iNaturalist-obs-NeoMapas.rds"))

lookup <- c(name="scientific_name",
            user="user_login",
            #date="observed_on",
            taxonid="id",
            taxon="iconic_taxon_name",
            kingdom="taxon_kingdom_name",
            phylum="taxon_phylum_name",
            class="taxon_class_name",
            order="taxon_order_name",
            genus="taxon_genus_name"
            )

JR_obs <- JR_obs %>%
  mutate(date=ymd(observed_on), 
        filter1 = grepl("Muestreos de NeoMapas", tag_list),
        URA=str_extract(tag_list,"NM[0-9]+")) %>%
  rename(any_of(lookup))

NeoMapas_obs <- JR_obs %>% 
  filter(latitude > 0,
         longitude < -60,
         filter1 | year(date) %in% 2003:2012) %>%
  st_as_sf(coords=c("longitude","latitude"), crs=4326)

qry <- st_intersects(NeoMapas_obs,CNEB)

NeoMapas_obs[lengths(qry)==1,"CN"] <- {CNEB %>% slice(unlist(qry)) %>% pull(cdg)}

NeoMapas_obs <- NeoMapas_obs %>% 
  mutate(unidad=case_when(
    !is.na(URA) & !is.na(CN) ~ sprintf("%s (%s)",URA,CN),
    !is.na(CN) ~ sprintf("celda %s",CN),
    TRUE ~ "sin información"))
    

obs_byyear <-  as.data.frame(table(year(NeoMapas_obs$date)))

colnames(obs_byyear) <- c("Año","Observaciones") 

```


Column1{.tabset .tabset-fade data-width=250}
-------

Tablas de observaciones por:

### Unidades regionales de NeoMapas {data-width=245}

```{r uralist}

NeoMapas_obs %>% 
  st_drop_geometry() %>%
  group_by("Unidades regionales"=unidad) %>% 
  summarise(Observaciones=n_distinct(date), Registros=n()) %>%
  arrange(desc(Observaciones)) %>%
  slice_head(n = 20) %>% 
  knitr::kable()
```

### Especies {data-width=245}
```{r taxalist}

NeoMapas_obs %>% 
  st_drop_geometry() %>%
  group_by("Especies"=name) %>% 
  summarise(Observaciones=n_distinct(date), Registros=n()) %>%
  arrange(desc(Observaciones)) %>%
  slice_head(n = 20) %>% 
  knitr::kable()
```

### Lugares {data-width=245}

```{r sitelist}

NeoMapas_obs %>% 
  st_drop_geometry() %>%
  group_by("Lugar"=place_guess) %>% 
  summarise(Observaciones=n_distinct(date), Registros=n()) %>%
  arrange(desc(Observaciones)) %>%
  slice_head(n = 20) %>% 
  knitr::kable()
```


Column2 {.tabset .tabset-fade}
-------

### Mapa
```{r map, eval = TRUE}



#NeoMapas_obs_sf <-  %>% select(any_of(c("name","date","taxon","common_name", 
#      "scientific_name", "image_url", "url"))) 

popup_html <- with(NeoMapas_obs,
                   sprintf("<p><b>%s</b><br/><i>%s</i></p>
                           <p>Observada en <u>%s</u> el %s<br/>
                           <p>
                           <img src='%s' width='200'/><br/>
                           <a href='%s' target='inat'>Ver en iNaturalist</a>
                           </p>", 
                           common_name,  name, unidad,
                           date, image_url,url))

#tmap_mode("view")
CNEB_slc <- CNEB %>% 
    filter(UM>0) %>%
    select(celda=cdg)

map1 <- tm_shape(CNEB_slc) + 
  tm_polygons(alpha=.33) +
  tm_minimap()

tmap_leaflet(map1) %>% leaflet::addMarkers(data = NeoMapas_obs,
                   popup = ~popup_html)
  
```


### Phylum 
```{r donut}
##numbers of observations by phylum 
taxranks = as.data.frame(table(NeoMapas_obs$taxon))
##Donut plot
p = taxranks %>% plot_ly(labels = ~Var1, values=~Freq) %>% 
  add_pie(hole=0.6) %>% 
  layout(title = ~paste0("Numero total de Taxa: ", length(unique(NeoMapas_obs$taxonid)))) 

plotly::config(p,displayModeBar = F) 
```

### Observaciones por año
```{r obsbyyear}
#plot number of observation by date 
ggplot(obs_byyear, aes(x=Año,y=Observaciones,group=1)) + geom_line() + geom_point()+ xlab("Año") + ylab("Observaciones") + theme_minimal()

```


### Calendario de observaciones
```{r calobs2022}
inat_obs_day <- NeoMapas_obs %>% 
  transmute(obs_year=year(date),
            obs_day=yday(date)) %>% 
  group_by(obs_year,obs_day,.groups = "drop") %>%
  summarise(Freq=n()) %>% 
  mutate(obs_day=as.numeric(as.character(obs_day)))


ggplot(inat_obs_day,aes(x=obs_day,y=obs_year,size=Freq)) + 
  geom_point() +
  labs(x="Día del año",
       y="Año",
       size = "Nr. de observaciobes") + 
  theme_minimal()

```

Column3{data-width=150}
-------

### Números
```{r}
#spp 
nspp = length(unique(NeoMapas_obs$name))
milestone <- ceiling(nspp/100)*100
gauge(nspp, min=0, max=milestone,label="Taxa")

qual = sum(NeoMapas_obs$quality_grade %in% "research")
gauge(qual, min=0, max=nrow(NeoMapas_obs),label="Obs. con grado de\ninvestigación")

```