Skip to content

Instantly share code, notes, and snippets.

@idshklein
Created February 16, 2022 12:28
Show Gist options
  • Save idshklein/5fa53b6d35f427df9a8493ddd73954c1 to your computer and use it in GitHub Desktop.
Save idshklein/5fa53b6d35f427df9a8493ddd73954c1 to your computer and use it in GitHub Desktop.
library(rwhatsapp)
library(tidyverse)
library(sf)
library(ggspatial)
library(lubridate)
library(gridExtra)
library(patchwork)
library(hms)
library(gganimate)
Sys.setlocale(locale = "hebrew")
yesterday <- today() - 1
chat <- rwa_read("D:/Downloads/WhatsApp Chat with גללי כלבים מיקומים בלבד.txt") %>%
mutate(location = map_chr(text,~str_split(.,"=")[[1]][2]),
lat = map_chr(location,~str_split(.,",")[[1]][1]),
lon = map_chr(location,~str_split(.,",")[[1]][2]),
date = ymd(as_date(time))) %>%
filter(!is.na(location),
date == yesterday) %>%
st_as_sf(coords = c("lon","lat"),crs = 4326)
p1 <- chat %>%
ggplot() +
annotation_map_tile(zoom = 16) +
geom_sf(color = "red",size = 5) +
labs(title = paste0("דיווחי צואת כלבים בתאריך ", yesterday),
subtitle = paste0('סה"כ דווחו ',nrow(chat)," דיווחים על ידי ", length(unique(chat$author)), " אנשים")) +
theme(plot.title = element_text(hjust = 1,size = 30),
plot.subtitle = element_text(hjust = 1,size = 30))
p2 <- chat %>%
st_drop_geometry() %>%
count(author) %>%
rename(reported = author, `number of times` = n) %>%
arrange(-`number of times`) %>%
tableGrob(theme = ttheme_minimal(), rows = NULL) %>%
grid.arrange()
p1
p1 / p2
rwa_read("D:/Downloads/WhatsApp Chat with גללי כלבים מיקומים בלבד.txt") %>%
filter(str_detect(text,"location")) %>%
mutate(location = map_chr(text,~str_split(.,"=")[[1]][2]),
lat = map_chr(location,~str_split(.,",")[[1]][1]),
lon = map_chr(location,~str_split(.,",")[[1]][2]),
date = ymd(as_date(time)),
hour = strftime(time,"%H:%M:%S")) %>%
filter(!is.na(location)) %>%
st_as_sf(coords = c("lon","lat"),crs = 4326) %>%
# st_write("dog_poo.shp")
ggplot() +
annotation_map_tile(zoom = 16) +
geom_sf(size = 5,mapping = aes(color = date))
chat <- rwa_read("C:/Users/User/Downloads/WhatsApp Chat with גללי כלבים מיקומים בלבד (5).txt") %>%
mutate(location = map_chr(text,~str_split(.,"=")[[1]][2]),
lat = map_chr(location,~str_split(.,",")[[1]][1]),
lon = map_chr(location,~str_split(.,",")[[1]][2]),
date = ymd(as_date(time))) %>%
filter(!is.na(location)) %>%
st_as_sf(coords = c("lon","lat"),crs = 4326)
anim_poo <- chat %>%
mutate(date = as_date(time)) %>%
group_by(date) %>%
summarise(n = n(), np = length(unique(author)))
ani <- anim_poo %>%
ggplot()+
annotation_map_tile() +
geom_sf(color = "red",size = 5)+
transition_manual(date) +
labs(title = "דיווחי צואת כלבים בתאריך {current_frame}",
subtitle = 'סה"כ דווחו {anim_poo$n[anim_poo$date == current_frame]} דיווחים על ידי {anim_poo$np[anim_poo$date == current_frame]} אנשים') +
theme(plot.title = element_text(hjust = 1,size = 30),
plot.subtitle = element_text(hjust = 1,size = 30))
animate(ani,duration = 20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment