In-class Exercise 3

Author

Eugene Toh

Published

October 28, 2024

install.packages("maptools", repos = "https://packagemanager.posit.co/cran/2023-10-13")
sg_sf <- mpsz_sf %>% st_union()

The analog of ppp and owin in sf. The as.* methods are used for conversion which can convert from data-frames which is essentially how SFOs are represented.

The reason why as.SpatialGridDataFrame.im does not work is because maptools is not installed.

pacman::p_load(dplyr, sf, tidyverse, tmap)
acled_sf <- read_csv("data/ACLED_Myanmar.csv") %>% st_as_sf(coords = c("longitude", "latitude"), crs = 4326) %>% st_transform(crs = 32647) %>% mutate(event_date = dmy(event_date))
Rows: 55574 Columns: 31
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (20): event_id_cnty, event_date, disorder_type, event_type, sub_event_ty...
dbl (11): year, time_precision, inter1, inter2, interaction, iso, latitude, ...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
tmap_mode("view")
acled_sf %>% filter(year == 2023 | event_type == "Political violence") %>% tm_shape() + tm_dots()
tmap_mode("plot")