knitr::opts_chunk$set(echo = FALSE,
                      warning = FALSE,
                      message = FALSE)
cfid <- facilities[[i, 'facility_id']]
fname <- facilities[[i, 'facility_name']]
ftype <- tolower(facilities[[i, 'type']])

facility_data_tmp <- facility_data %>% 
  dplyr::filter(fid == cfid)
 write(paste0("Map: ", fname), stderr())
gps_coordinates <- timci::process_gps_coordinates(facility_data_tmp)
# Convert GPS coordinates to an sf object
screening_points <- sf::st_as_sf(gps_coordinates, coords = c("longitude", "latitude"), crs = 4326)
shape_pathname <- system.file(file.path('extdata', "maps", "India", "gadm36_IND_2.shp"), package = 'timci')
indian_districts <- sf::st_read(shape_pathname,
                                stringsAsFactors=FALSE,
                                quiet = TRUE)
up_districts <- indian_districts[indian_districts$NAME_1 == "Uttar Pradesh", ]
rm(indian_districts)
deoria_dc <- up_districts[up_districts$NAME_2 == "Deoria", ]
sitapur_dc <- up_districts[up_districts$NAME_2 == "Sitapur", ]
unnao_dc <- up_districts[up_districts$NAME_2 == "Unnao", ]
# Set plot layout
layout(mat = matrix(c(1, 1, 1,
                      1, 1, 1,
                      2, 3, 4,
                      2, 3, 4),
                    nrow = 4,
                    byrow = TRUE))

# Plot 1: Uttar Pradesh map
graphics::par(mar = c(0, 0, 0, 0))
plot(sf::st_geometry(up_districts),
     col="gray81",
     border="gray70")
plot(sf::st_geometry(deoria_dc),
     col = "#fc7969",
     lwd = 1,
     add=TRUE)
text(sf::st_coordinates(st_centroid(st_geometry(deoria_dc), of_largest_polygon=TRUE)+c(0, 0.7)),
     label = "Deoria",
     cex = 1,
     font = 2)
plot(sf::st_geometry(sitapur_dc),
     col = "#fc7969",
     lwd = 1,
     add=TRUE)
text(sf::st_coordinates(st_centroid(st_geometry(sitapur_dc), of_largest_polygon=TRUE)+c(0, 0.7)), label = "Sitapur", cex = 1, font = 2)
plot(sf::st_geometry(unnao_dc), col = "#fc7969", lwd = 1, add=TRUE)
text(sf::st_coordinates(st_centroid(st_geometry(unnao_dc), of_largest_polygon=TRUE)+c(0, -0.7)), label = "Unnao", cex = 1, font = 2)
points(sf::st_coordinates(screening_points),
       pch = 21,
       bg = "#000000")

# Plot 2: Deoria
graphics::par(mar = c(0, 0, 0, 0))
plot(sf::st_geometry(deoria_dc),
     col="gray81",
     border="gray70",
     lwd = 1)
points(sf::st_coordinates(screening_points),
       pch = 21,
       bg = "#000000")
title("Deoria", line = -1)

# Plot 3: Sitapur
graphics::par(mar = c(0, 0, 0, 0))
plot(sf::st_geometry(sitapur_dc),
     col="gray81",
     border="gray70",
     lwd = 1)
points(sf::st_coordinates(screening_points),
       pch = 21,
       bg = "black")
title("Sitapur", line = -1)

# Plot 3: Unnao
graphics::par(mar = c(0, 0, 0, 0))
plot(sf::st_geometry(unnao_dc),
     col="gray81",
     border="gray70",
     lwd = 1)
points(sf::st_coordinates(screening_points),
       pch = 21,
       bg = "black")
title("Unnao", line = -1)
rm(up_districts)
rm(deoria_dc)
rm(sitapur_dc)
rm(unnao_dc)
tmp <- gc() # garbage collection
shape_pathname <- system.file(file.path('extdata', "maps", "Kenya", "gadm36_KEN_1.shp"), package = 'timci')
kenyan_counties <- sf::st_read(shape_pathname,
                               stringsAsFactors=FALSE,
                               quiet = TRUE)
kakamega <- kenyan_counties[kenyan_counties$NAME_1 == "Kakamega", ]
uasingishu <- kenyan_counties[kenyan_counties$NAME_1 == "Uasin Gishu", ]
kitui <- kenyan_counties[kenyan_counties$NAME_1 == "Kitui", ]
# Set plot layout
layout(mat = matrix(c(1, 1, 1,
                      1, 1, 1,
                      2, 3, 4,
                      2, 3, 4),
                    nrow = 4,
                    byrow = TRUE))

# Plot 1: Kenya map
graphics::par(mar = c(0, 0, 0, 0))
plot(sf::st_geometry(kenyan_counties),
     col="gray81",
     border="gray70")
plot(sf::st_geometry(kakamega),
     col = "#fc7969",
     lwd = 1,
     add=TRUE)
text(sf::st_coordinates(st_centroid(st_geometry(kakamega), of_largest_polygon=TRUE)+c(0, 0.7)),
     label = "Kakamega",
     cex = 1,
     font = 2)
plot(sf::st_geometry(uasingishu),
     col = "#fc7969",
     lwd = 1,
     add=TRUE)
text(sf::st_coordinates(st_centroid(st_geometry(uasingishu), of_largest_polygon=TRUE)+c(0, 0.7)), label = "Uasin Gishu", cex = 1, font = 2)
plot(sf::st_geometry(kitui), col = "#fc7969", lwd = 1, add=TRUE)
text(sf::st_coordinates(st_centroid(st_geometry(kitui), of_largest_polygon=TRUE)+c(0, -0.7)), label = "Kitui", cex = 1, font = 2)
points(sf::st_coordinates(screening_points),
       pch = 21,
       bg = "#000000")

# Plot 2: Kakamega
graphics::par(mar = c(0, 0, 0, 0))
plot(sf::st_geometry(kakamega),
     col="gray81",
     border="gray70",
     lwd = 1)
points(sf::st_coordinates(screening_points),
       pch = 21,
       bg = "#000000")
title("Kakamega", line = -1)

# Plot 3: Uasin Gishu
graphics::par(mar = c(0, 0, 0, 0))
plot(sf::st_geometry(uasingishu),
     col="gray81",
     border="gray70",
     lwd = 1)
points(sf::st_coordinates(screening_points),
       pch = 21,
       bg = "black")
title("Uasin Gishu", line = -1)

# Plot 3: Kitui
graphics::par(mar = c(0, 0, 0, 0))
plot(sf::st_geometry(kitui),
     col="gray81",
     border="gray70",
     lwd = 1)
points(sf::st_coordinates(screening_points),
       pch = 21,
       bg = "black")
title("Kitui", line = -1)
rm(kenyan_counties)
rm(kakamega)
rm(uasingishu)
rm(kitui)
tmp <- gc() # garbage collection
shape_pathname <- system.file(file.path('extdata', "maps", "Senegal", "gadm36_SEN_1.shp"), package = 'timci')
senegal_regions <- sf::st_read(shape_pathname,
                               stringsAsFactors=FALSE,
                               quiet = TRUE)
thies <- senegal_regions[senegal_regions$NAME_1 == "Thiès", ]
# Plot: Senegal map
graphics::par(mar = c(0, 0, 0, 0))
plot(sf::st_geometry(thies),
     col= "#fc7969",
     border= "#fc7969")
points(sf::st_coordinates(screening_points),
       pch = 21,
       bg = "#000000")
rm(senegal_regions)
rm(thies)
tmp <- gc() # garbage collection


Thaliehln/timci documentation built on April 8, 2024, 3:38 p.m.