Good day.
I’m working on mapping a certain type of facility per city/municipality (CityMun) in two provinces. Some municipalities have no or zero frequencies. I was able to map the municipalities with facilities but those with zero frequencies disappeared from the map. The map looked like separate islands because of empty areas. I’m not sure what went wrong with my codes, perhaps on removing of the duplicates or changing NAs to zeros or the specifying the colors (which are low mid and high)?
I hope you can guide me.
Thank you so much.
Respectfully,
Echo
#shapefile data
ph_base_layer_nat <-
read_sf(here("shapefiles", "gadm41_PHL_3.shp")) %>%
rename(Province = NAME_1,
CityMun = NAME_2,
Brgy = NAME_3) %>%
select(-GID_3,
-GID_0,
-COUNTRY,
-GID_1,
-GID_2,
-VARNAME_3,
-NL_NAME_3,
-NL_NAME_2,
-NL_NAME_1,
-TYPE_3,
-CC_3,
-HASC_3,
-ENGTYPE_3) %>%
filter(Province== "Samar"|Province== "Southern Leyte")
#Remove Duplicate LGU (CityMun) and keep other variables
ph_base_layer_nat1 <- distinct(ph_base_layer_nat, CityMun, .keep_all = TRUE)
#AFHF per LGU
CityMun<- c("Tommas Oppus",
"Limasawa",
"Liloan",
"Maasin City",
"Padre Burgos",
"Macrohon",
"Sogod",
"Malitbog",
"Bontoc",
"Libagon",
"Villareal",
"Marabut",
"San Sebastian",
"Catbalogan",
"Calbayog City",
"Basey",
"Paranas",
"San Jose de Buan",
"Santa Rita",
"Calbiga"
)
CertifiedFacilities <- c(1,
1,
1,
3,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
4,
1,
1,
1,
1,
1)
AFHF <- data.frame(CityMun, CertifiedFacilities)
#Remove Brgy
ph_base_layer_nat2 <- ph_base_layer_nat1 %>%
select(Province,
CityMun,
geometry)
# Merge the AFHF data with the shapefile data
ph_base_layer_nat3 <-
left_join(ph_base_layer_nat2, AFHF)
#Replace NA with Zero
ph_base_layer_nat3[is.na(ph_base_layer_nat3)] <- 0
breaks <- c(0,1,2,3,4,5)
low_color <- "blue"
mid_color <- "yellow"
high_color <- "orange"
#AFHF Map
AFHF_map <- ggplot(ph_base_layer_nat3) +
geom_sf(aes(fill = CertifiedFacilities)) +
scale_fill_gradient2(
breaks = breaks,
low = low_color,
mid = mid_color,
high = high_color) +
geom_sf_text(data = ph_base_layer_nat3, aes(label = CityMun, geometry = geometry),
size = 2.0, color = "black", check_overlap = TRUE) +
theme_minimal() +
theme(legend.title = element_text(size = 10),
legend.text = element_text(size = 6)) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) +
theme(axis.title.x = element_blank(), # Remove x-axis title
axis.title.y = element_blank(), # Remove y-axis title
axis.text.x = element_blank(), # Remove x-axis labels
axis.text.y = element_blank()) + # Remove y-axis labels
labs(fill = "Adolescent Friendly Health Facilities\n(as of Dec 2023)",
caption = "No.of AFHFs per LGU, Province of __ and __, Philippines")
tibble::tribble(
~Province, ~CityMun, ~CertifiedFacilities, ~geometry,
"Samar", "Almagro", 0, "list(list(c(124.312492371, 124.312561035, 124.312911988, 124.313423157, 124.313880921, 124.314247131, 124.314537047, 124.314910889, 124.316947937, 124.316947937, 124.317222595, 124.31742096, 124.318611145, 124.318626404, 124.31865692, 124.318893434, 124.318893434, 124.318946839, 124.319107056, 124.319061279, 124.31891632, 124.318817138, 124.318946839, 124.319000244, 124.319381714, 124.319732666, 124.321907043, 124.323349, 124.317359924, 124.315887451, 124.312866211, 124.312492371, 11.9536695480002,
11.9537200930001, 11.9540395730001, 11.9543304440001, 11.9543504720002, 11.9541997910001, 11.9540004740002, 11.95361042, 11.951390266, 11.9508304600001, 11.9505596170001, 11.9505596170001, 11.9505596170001, 11.951390266, 11.951519967, 11.952219963, 11.9530601500002, 11.9531898500001, 11.9537096020001, 11.954210281, 11.9544601450001, 11.9546203620001, 11.9550104140001, 11.9551095960001, 11.955619812, 11.956089974, 11.9484462730001, 11.9423398970002, 11.9388399130002, 11.9434900290001, 11.953140258,
11.9536695480002)))",
"Samar", "Basey", 1, "list(list(c(125.011383056, 125.010986327, 125.010406495, 125.009941101, 125.009498595, 125.009147644, 125.008773804, 125.008422852, 125.008079529, 125.007789612, 125.007583618, 125.007507324, 125.007499694, 125.007499694, 125.007537841, 125.007713319, 125.007957458, 125.007751465, 125.007400512, 125.006767272, 125.005798339, 125.004470825, 125.002998353, 125.001602173, 125.001487732, 125.00026703, 125, 124.999732972, 124.998908996, 124.998847961, 124.998657227, 124.998580933, 124.998390197, 124.998283387,
124.998046876, 124.997779846, 124.997543335, 124.997497558, 124.997497558, 124.997451783, 124.997268677, 124.997566223, 124.998161316, 125.009979248, 125.011383056, 11.2757501610001, 11.275589944, 11.2753801340001, 11.2750101090001, 11.274609565, 11.2741603850001, 11.2737503050001, 11.273349761, 11.2729702010001, 11.272580148, 11.2721500400002, 11.2716703420001, 11.271169662, 11.2706403740002, 11.2701101300001, 11.2695798870001, 11.2686195370002, 11.2682695380001, 11.267720223, 11.267720223, 11.2677898410001,
11.2680597310001, 11.268480301, 11.2690296170002, 11.2690696710001, 11.2694396980001, 11.270000457, 11.2702703470002, 11.2711296080001, 11.2716703420001, 11.2721204760001, 11.2726097110001, 11.2730197910001, 11.27342987, 11.273770333, 11.2742204670001, 11.2748003020001, 11.275440217, 11.2760000230001, 11.276459694, 11.2768001560001, 11.2769603730002, 11.2773895260001, 11.28110981, 11.2757501610001)))",
"Samar", "Calbayog City", 4, "list(list(c(124.54107666, 124.544960022, 124.549491882, 124.554412842, 124.556678771, 124.559013366, 124.557777405, 124.556838989, 124.555793762, 124.555412292, 124.554710389, 124.553749084, 124.553627013, 124.552597045, 124.552223205, 124.552093506, 124.551971436, 124.551208495, 124.550163269, 124.549171447, 124.548530579, 124.54789734, 124.547828674, 124.546112061, 124.545730591, 124.545211792, 124.544776916, 124.544776916, 124.544517516, 124.544250489, 124.54385376, 124.543380738, 124.543121338,
124.542602539, 124.542251587, 124.54107666, 12.100090027, 12.1104602820001, 12.1186800000001, 12.1216001520001, 12.1194295880001, 12.117710115, 12.1077604290002, 12.106419563, 12.1066303260002, 12.10597992, 12.105939866, 12.1057596200001, 12.105319977, 12.1055402750001, 12.1057596200001, 12.105319977, 12.1047801970001, 12.1044502260001, 12.10447979, 12.1042299280002, 12.1037998200001, 12.10324955, 12.1024799340001, 12.102729798, 12.102470398, 12.102549552, 12.102319718, 12.1018695830002, 12.1013498310002,
12.1013498310002, 12.101010322, 12.1007499700002, 12.1009702680001, 12.1009702680001, 12.100520134, 12.100090027)))"
)
#> # A tibble: 3 × 4
#> Province CityMun CertifiedFacilities geometry
#> <chr> <chr> <dbl> <chr>
#> 1 Samar Almagro 0 "list(list(c(124.312492371, 124.31…
#> 2 Samar Basey 1 "list(list(c(125.011383056, 125.01…
#> 3 Samar Calbayog City 4 "list(list(c(124.54107666, 124.544…