Play around some more

master
Marvin Johanning 2022-07-17 21:43:18 +02:00
parent 89d4e756c0
commit 6ab8928049
4 changed files with 27 additions and 36 deletions

0
.Rapp.history Normal file
View File

View File

@ -4,9 +4,10 @@ library(sf)
library(mapview)
library(dplyr)
library(ggrepel)
#Set working directory
setwd("/Users/mjo-air/Programming/R")
library(grid)
library(tidyverse)
library(shadowtext)
library(magrittr)
#Choose Scythebird export
locations <- read.csv(file=file.choose(), stringsAsFactors = F)[,c('Location.1', 'Common', 'Number')]
@ -15,8 +16,6 @@ locations <- read.csv(file=file.choose(), stringsAsFactors = F)[,c('Location.1',
locations$Number<-gsub(">","",as.character(locations$Number))
locations$Number<-gsub("~","",as.character(locations$Number))
#Do a tibblings
locations <- as_tibble(locations)
@ -30,6 +29,7 @@ per_location_by_species <- locations %>%
arrange(desc(sum))
per_location_by_species <- subset(per_location_by_species, Common!="Stockente")
per_location_by_species$Location.1 <- gsub("\\s*\\[[^\\)]+\\]","",as.character(per_location_by_species$Location.1))
#Bar plot
ggplot(per_location_by_species, aes(sum, Common, fill = Location.1)) +
@ -38,10 +38,4 @@ ggplot(per_location_by_species, aes(sum, Common, fill = Location.1)) +
print(per_location_by_species)
# Create mapview map
locations_sf <- st_as_sf(per_location, coords = c("COORD_LON", "COORD_LAT"), crs = 4326)
mapview(locations_sf, zcol="sum")
print(locations)

View File

@ -7,15 +7,15 @@ library(ggrepel)
library(magrittr)
#Google API key
register_google(key = "")
#register_google(key = "")
#Google Maps view
stauteich_3 <- get_googlemap("bielefeld stauteich III", zoom = 14, maptype = "satellite")
stauteich_3 <- get_googlemap("Obersee Bielefeld", zoom = 14, maptype = "satellite")
#Set working directory
setwd("/Users/mjo-air/Programming/R")
#setwd("/Users/mjo-air/Programming/R")
#Choose Ornihto export
#Choose Ornitho export
locations <- read.csv(file=file.choose(), sep = "\t")[,c('COORD_LAT', 'COORD_LON', 'TOTAL_COUNT', 'NAME_SPECIES', 'PLACE')]
#Remove first row
@ -30,22 +30,22 @@ locations$COORD_LAT %<>% as.double
locations$TOTAL_COUNT %<>% as.integer
#Total number of birds per location
#per_location <- locations %>%
# group_by(PLACE, COORD_LAT, COORD_LON) %>%
#summarise(sum = sum(TOTAL_COUNT)) %>%
#arrange(desc(sum))
#Total number of birds if Psalm is stupid
per_location <- locations %>%
group_by(PLACE) %>%
mutate(across(starts_with("COORD_"), last)) %>%
ungroup()
per_location <- per_location %>%
per_location <- locations %>%
group_by(PLACE, COORD_LAT, COORD_LON) %>%
summarise(sum = sum(TOTAL_COUNT)) %>%
arrange(desc(sum))
#Total number of birds if Psalm is stupid 1
#per_location <- locations %>%
# group_by(PLACE) %>%
# mutate(across(starts_with("COORD_"), last)) %>%
# ungroup()
#Total number of birds if Psalm is stupid 2
#per_location <- per_location %>%
# group_by(PLACE, COORD_LAT, COORD_LON) %>%
# summarise(sum = sum(TOTAL_COUNT)) %>%
# arrange(desc(sum))
#Remove text in brackets
per_location$PLACE <- gsub("\\s*\\[[^\\)]+\\]","",as.character(per_location$PLACE))

View File

@ -8,23 +8,17 @@ library(grid)
library(tidyverse)
library(shadowtext)
#Working directory
setwd("/Users/mjo-air/Programming/R")
#Colours
BLUE <- "#076fa2"
#API key for Google Maps
register_google(key = "")
#Map of Bielefeld, centered on Stauteich 3
stauteich_3 <- get_googlemap("bielefeld stauteich III", zoom = 14, maptype = "satellite")
bielefeld <- get_googlemap("Tieplatz Heepen Bielefeld", zoom = 13, maptype = "satellite")
#The variable used to get the sum of all birds that were seen at a particular location
#all_birds_sum_var <- read.csv("birding.csv", stringsAsFactors = F, na.strings="`")[,c('Location.1', 'Longitude', 'Latitude', 'Number', 'Common')]
#The variable used to get the sum of unique birds that were seen at a particular location
unique_birds_sum_var <- read.csv("birding.csv", stringsAsFactors = F, na.strings="`")[,c('Location.1', 'Longitude', 'Latitude', 'Common')]
unique_birds_sum_var <- read.csv(file=file.choose(), stringsAsFactors = F, na.strings="`")[,c('Location.1', 'Longitude', 'Latitude', 'Common')]
#Convert to tibble
locations <- as_tibble(unique_birds_sum_var)
@ -32,6 +26,9 @@ locations <- as_tibble(unique_birds_sum_var)
#Find how many unique sightings there are in this location
per_location_unique <- unique(locations)
#Remove text in brackets
per_location_unique$Location.1 <- gsub("\\s*\\[[^\\)]+\\]","",as.character(per_location_unique$Location.1))
#Do some grouping
per_location <- per_location_unique %>%
group_by(Location.1, Longitude, Latitude) %>%
@ -55,7 +52,7 @@ ggplot(per_location) +
geom_col(aes(sum, Location.1), fill = BLUE, width = 0.6)
#Google Maps map
ggmap(bw_map) +
ggmap(bielefeld) +
geom_point(data = per_location,
aes(x = Longitude, y = Latitude, size=sum),
color = "red", alpha = 0.5) +