Mindanao Sustainable Agrarian & Agriculture Development (MinSAAD)

Installing Packages

After installing the packages listed in the library below, proceed to create a database connection in the MySQL Server.

library(RODBC)
library(DBI)
library(odbc)

To enable data visualization, install the ggplot, dplyr, stringr and ggh4x package.

library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
library(stringr)
library(ggh4x)
library(kableExtra)
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
To establish a connection with the MySQL Server, you need to create a database connection via Data Source Name (DSN).
con <- dbConnect(odbc::odbc(), dsn = "minsaad_mysql")
Retrieve a list of Component records along with the corresponding number of Sub-Components.
Utilize the following SQL statement to access the Components table within the database. To retrieve table(s) from the database and assign the data to a variable in R, you can use the following SQL statement:
vComponents <- dbGetQuery(con, 'SELECT
                                    components.ComponentName AS Components, 
                                    components.ComponentCode AS `Code`, 
                                    Count(subcomponents.SubComponentID_PK) AS SubComponents
                                FROM
                                    components
                                    INNER JOIN
                                    subcomponents
                                    ON 
                                        components.ComponentID_PK = subcomponents.ComponentID_FK
                                GROUP BY
                                    components.ComponentName, 
                                    components.ComponentCode
                                ORDER BY
                                    components.ComponentCode ASC;')
To view the Components table within the database, you can follow the command below:
# Make dataframe
results_df <- data.frame(vComponents, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("Component", "Code", "No. of Sub-Components", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Components table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Components table
Component Code No. of Sub-Components
Agriculture, Agribusiness, and Agro-forestry Development AAAD 4
Support Infrastructure INFRA 5
Institutional Development INSTI 5
Monitoring and Evaluation M&E 2
Project Management PM 2
Total: 18
To display a chart illustrating the records of Components along with the corresponding number of Sub-Components using the ggplot command in R.
ggplot(vComponents, aes(x=Code, as.integer(SubComponents), y=as.integer(SubComponents), fill=Code)) +
  geom_col(show.legend = TRUE) +
  geom_text(aes(label = as.integer(SubComponents), y = as.integer(SubComponents) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="Components")) +
  xlab("Components") + ylab("Number of Sub-Components") +
  labs(title= "Major Components with Number of Sub-Components",  
       caption="Data Collected by: Junald A. Lagod")

To retrieve a list of Sub-Component records along with the Components table.
To access the Sub-Components table within the database and retrieve its data while assigning it to a variable in R, you can follow the example below:
vSubComponents_POs <- dbGetQuery(con, 'SELECT
                                          components.ComponentCode AS Component, 
                                          subcomponents.SubComponentName AS `Sub-Component`, 
                                          subcomponents.SubComponentCode AS `Code`, 
                                          COUNT(pogroup.POID_PK) AS POs,
                                          SUM(pogroup.ARBMale ) AS ARBMale,
                                          SUM(pogroup.ARBFemale ) AS ARBFemale,
                                          SUM(pogroup.NonARBMale ) AS NonARBMale,
                                          SUM(pogroup.NonARBFemale ) AS NonARBFemale,
                                          SUM(pogroup.IPMale ) AS IPMale,
                                          SUM(pogroup.IPFemale ) AS IPFemale,
                                          SUM(pogroup.NonIPMale ) AS NonIPMale,
                                          SUM(pogroup.NonIPFemale ) AS NonIPFemale
      
                                        FROM
                                          components
                                          LEFT JOIN
                                          subcomponents
                                          ON 
                                              components.ComponentID_PK = subcomponents.ComponentID_FK
                                          LEFT JOIN
                                          pogroup
                                          ON 
                                              pogroup.POTypeID_FK = subcomponents.SubComponentID_PK
                                        GROUP BY
                                          components.ComponentCode, 
                                          subcomponents.SubComponentName, 
                                          subcomponents.SubComponentCode
                                        ORDER BY
                                          components.ComponentCode ASC, 
                                          subcomponents.SubComponentName ASC;')

vSubComponents_SPs <- dbGetQuery(con, 'SELECT
                                            components.ComponentCode AS Component, 
                                            subcomponents.SubComponentName AS `Sub-Component`, 
                                            subcomponents.SubComponentCode AS `Code`, 
                                            COUNT(subprojects.SPID_PK) AS SPs,
                                            SUM(subprojects.Ben) AS Beneficiaries,
                                            SUM(subprojects.Qty) AS Qty,
                                            (CASE 
                                                    WHEN subcomponents.SubComponentCode = "AGBiz" THEN "Has"
                                                    WHEN subcomponents.SubComponentCode = "AGRI" THEN "Has"
                                                    WHEN subcomponents.SubComponentCode = "AGRO" THEN "Has"
                                                    WHEN subcomponents.SubComponentCode = "CI" THEN "Has"
                                                    WHEN subcomponents.SubComponentCode = "BRDG" THEN "Lms"
                                                    WHEN subcomponents.SubComponentCode = "FMR" THEN "Kms"
                                                    WHEN subcomponents.SubComponentCode = "IRRIG" THEN "Has"
                                                    WHEN subcomponents.SubComponentCode = "PHF" THEN "Units"
                                                    WHEN subcomponents.SubComponentCode = "RWS" THEN "HHs"
                                            END) AS UnitMeasure
                                        FROM
                                            components
                                            LEFT JOIN
                                            subcomponents
                                            ON 
                                                components.ComponentID_PK = subcomponents.ComponentID_FK
                                            LEFT JOIN
                                            subprojects
                                            ON 
                                                subcomponents.SubComponentID_PK = subprojects.SPTypeID_FK
                                        GROUP BY
                                            components.ComponentCode, 
                                            subcomponents.SubComponentName, 
                                            subcomponents.SubComponentCode
                                        ORDER BY
                                            components.ComponentCode ASC, 
                                            subcomponents.SubComponentCode ASC;')
To view the Sub-Components table within the database, you can follow the command below:
# Make dataframe
vSubComponents_POs_tmp <- vSubComponents_POs %>%
  select(-ARBMale, -ARBFemale, -NonARBMale, -NonARBFemale, -IPMale, -IPFemale, -NonIPMale, -NonIPFemale)

vSubComponents_SPs_tmp <- vSubComponents_SPs %>%
  select(-Beneficiaries, -Qty, -UnitMeasure)

vSubComponents <- merge(vSubComponents_POs_tmp, vSubComponents_SPs_tmp)
vSubComponents_tmp <- vSubComponents

results_df <- data.frame(vSubComponents_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("Component", "Sub-Components", "Code", "No. of POs", "No. of SPs", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Sub-Components table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Sub-Components table
Component Sub-Components Code No. of POs No. of SPs
AAAD Agribusiness AGBiz 0 65
AAAD Agriculture AGRI 0 0
AAAD Agro-forestry AGRO 0 35
AAAD Crop Intensification CI 0 22
INFRA Bridge BRDG 0 15
INFRA Farm to Market Road FMR 0 40
INFRA Irrigation IRRIG 0 19
INFRA Post Harvest Facilities PHF 0 65
INFRA Rural Water Systems RWS 0 26
INSTI Cooperative COOP 68 0
INSTI Farmers Association FA 206 0
INSTI Irrigators Association IA 21 0
INSTI Water Users Association WUA 31 0
INSTI Womens Organization WO 23 0
M&E Management Information System MIS 0 0
M&E Monitoring and Evaluation M&E 0 0
PM Administration ADMIN 0 0
PM Finance FINCE 0 0
Total: 349 287
To retrieve a list of Sub-Component records for AAAD & INFRA along with the Components table.
# Make dataframe
vSubComponents_SPs <- vSubComponents_SPs %>%
  filter(vSubComponents_SPs$Component == "AAAD" | vSubComponents_SPs$Component == "INFRA") %>%
  #drop_na() %>%
  select(-Component)

results_df <- data.frame(vSubComponents_SPs, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("Sub-Components", "Code", "SPs", 
                       "Beneficiaries", "Qty", "Unit Measure", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Sub-Components table for AAAD & INFRA Components", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Sub-Components table for AAAD & INFRA Components
Sub-Components Code SPs Beneficiaries Qty Unit Measure
Agribusiness AGBiz 65 12000 11619.973 Has
Agriculture AGRI 0 NA NA Has
Agro-forestry AGRO 35 1311 7177.776 Has
Crop Intensification CI 22 200 5226.000 Has
Bridge BRDG 15 0 777.000 Lms
Farm to Market Road FMR 40 0 240.212 Kms
Irrigation IRRIG 19 0 1930.330 Has
Post Harvest Facilities PHF 65 0 88.000 Units
Rural Water Systems RWS 26 0 7077.000 HHs
Total: 287 NA NA
To display a chart illustrating the records of SP Types along with the corresponding number of Sub-Projects(SPs) using the ggplot command in R.
ggplot(vSubComponents_SPs, aes(x=Code, as.integer(SPs), y=as.integer(SPs), fill=Code)) +
  geom_col(show.legend = TRUE) +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 100, by = 10), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="SP Types")) +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  xlab("SP Types") + ylab("Number of Sub-Projects(SPs)") +
  labs(title= "SP Types with Number of Sub-Projects(SPs)",  
       caption="Data Collected by: Junald A. Lagod") 

To retrieve a list of Sub-Component records for INSTI along with the Components table.
vSubComponents_POs <- vSubComponents_POs %>%
  filter(vSubComponents_POs$Component == "INSTI") %>%
  select(-Component)

# Make dataframe
results_df <- data.frame(vSubComponents_POs, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("Sub-Components", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Sub-Components table for INSTITUTIONAL(INSTI) DEVELOPMENT", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Sub-Components table for INSTITUTIONAL(INSTI) DEVELOPMENT
Sub-Components Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 68 2756 2882 1081 1842 88 76 1669 2476
Farmers Association FA 206 5315 3077 983 1242 1451 673 2224 1755
Irrigators Association IA 21 544 168 72 20 103 35 144 61
Water Users Association WUA 31 1504 1072 440 210 761 520 592 301
Womens Organization WO 23 0 871 0 162 0 63 0 461
Total: 349 10119 8070 2576 3476 2403 1367 4629 5054
To display a chart illustrating the records of PO Types along with the corresponding number of Peoples Organizations(POs) using the ggplot command in R.
ggplot(vSubComponents_POs, aes(x=Code, as.integer(POs), y=as.integer(POs), fill=Code)) +
  geom_col(show.legend = TRUE) +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 250, by = 20), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="PO Types")) +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A",
                               "#BACCC1", "#3C8D53", "#FFF123")) +
  xlab("PO Types") + ylab("Number of Peoples Organizations(POs)") +
  labs(title= "PO Types with Number of Peoples Organizations(POs)",  
       caption="Data Collected by: Junald A. Lagod") 

To retrieve a list of PO Types with Status records along with the Components table.
To access the PO Types with Status table within the database and retrieve its data while assigning it to a variable in R, you can follow the example below:
vPOTypeStatus_OCR <- dbGetQuery(con, 'SELECT
                                        projstatus.Component, 
                                        projentities.EntityName AS "MajorStatus", 
                                        "Organizational Capacity" AS Rating, 
                                        "OCR" AS RatingCode, 
                                        subcomponents.SubComponentName AS "POType", 
                                        subcomponents.SubComponentCode AS "Code", 
                                        projstatus.ProjStatusID_PK AS StatusID, 
                                        projstatus.ProjStatusName AS "Status", 
                                        COUNT(pogroup.POID_PK) AS POs
                                      FROM
                                        components
                                        LEFT JOIN
                                        subcomponents
                                        ON 
                                            components.ComponentID_PK = subcomponents.ComponentID_FK
                                        LEFT JOIN
                                        pogroup
                                        ON 
                                            pogroup.POTypeID_FK = subcomponents.SubComponentID_PK
                                        LEFT JOIN
                                        projstatus
                                        ON 
                                            pogroup.OCRStatusID_FK = projstatus.ProjStatusID_PK
                                        INNER JOIN
                                        projentities
                                        ON 
                                            projstatus.MajorStatusID_FK = projentities.EntityID_PK
                                      WHERE
                                        components.ComponentCode = "INSTI"
                                      GROUP BY
                                        projstatus.Component, 
                                        projstatus.ProjStatusID_PK, 
                                        components.ComponentCode, 
                                        subcomponents.SubComponentName, 
                                        subcomponents.SubComponentCode, 
                                        projstatus.ProjStatusName
                                      ORDER BY
                                        components.ComponentCode ASC, 
                                        subcomponents.SubComponentName ASC;')

vPOTypeStatus_ERR <- dbGetQuery(con, 'SELECT
                                        projstatus.Component, 
                                        projentities.EntityName AS "MajorStatus", 
                                        "Enterprise Readiness" AS Rating, 
                                        "ERR" AS RatingCode, 
                                        subcomponents.SubComponentName AS "POType", 
                                        subcomponents.SubComponentCode AS "Code", 
                                        projstatus.ProjStatusID_PK AS StatusID, 
                                        projstatus.ProjStatusName AS "Status", 
                                        COUNT(pogroup.POID_PK) AS POs
                                      FROM
                                        components
                                        LEFT JOIN
                                        subcomponents
                                        ON 
                                            components.ComponentID_PK = subcomponents.ComponentID_FK
                                        LEFT JOIN
                                        pogroup
                                        ON 
                                            pogroup.POTypeID_FK = subcomponents.SubComponentID_PK
                                        LEFT JOIN
                                        projstatus
                                        ON 
                                            pogroup.ERRStatusID_FK = projstatus.ProjStatusID_PK
                                        INNER JOIN
                                        projentities
                                        ON 
                                            projstatus.MajorStatusID_FK = projentities.EntityID_PK
                                      WHERE
                                        components.ComponentCode = "INSTI"
                                      GROUP BY
                                        projstatus.Component, 
                                        projstatus.ProjStatusID_PK, 
                                        components.ComponentCode, 
                                        subcomponents.SubComponentName, 
                                        subcomponents.SubComponentCode, 
                                        projstatus.ProjStatusName
                                      ORDER BY
                                        components.ComponentCode ASC, 
                                        subcomponents.SubComponentName ASC;')



vPOTypeStatus_MLR <- dbGetQuery(con, 'SELECT
                                        projstatus.Component, 
                                        projentities.EntityName AS "MajorStatus", 
                                        "Maturity Level" AS Rating,  
                                        "MLR" AS RatingCode, 
                                        subcomponents.SubComponentName AS "POType", 
                                        subcomponents.SubComponentCode AS "Code", 
                                        projstatus.ProjStatusID_PK AS StatusID, 
                                        projstatus.ProjStatusName AS "Status", 
                                        COUNT(pogroup.POID_PK) AS POs
                                      FROM
                                        components
                                        LEFT JOIN
                                        subcomponents
                                        ON 
                                            components.ComponentID_PK = subcomponents.ComponentID_FK
                                        LEFT JOIN
                                        pogroup
                                        ON 
                                            pogroup.POTypeID_FK = subcomponents.SubComponentID_PK
                                        LEFT JOIN
                                        projstatus
                                        ON 
                                            pogroup.MaturityLevelID_FK = projstatus.ProjStatusID_PK
                                        INNER JOIN
                                        projentities
                                        ON 
                                            projstatus.MajorStatusID_FK = projentities.EntityID_PK
                                      WHERE
                                        components.ComponentCode = "INSTI"
                                      GROUP BY
                                        projstatus.Component, 
                                        projstatus.ProjStatusID_PK, 
                                        components.ComponentCode, 
                                        subcomponents.SubComponentName, 
                                        subcomponents.SubComponentCode, 
                                        projstatus.ProjStatusName
                                      ORDER BY
                                        components.ComponentCode ASC, 
                                        subcomponents.SubComponentName ASC;')
To display a chart illustrating the records of Cooperative PO Types along with the corresponding number of POs using the ggplot command in R.
vPOTypeStatus <- union(vPOTypeStatus_OCR, vPOTypeStatus_ERR)
vPOTypeStatus <- union(vPOTypeStatus, vPOTypeStatus_MLR)

vPOTypeStatus_COOP <- vPOTypeStatus %>%
  filter(vPOTypeStatus$Code == "COOP")%>%
  group_by(POType, Code, Rating, Status)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vPOTypeStatus_COOP) +
  geom_col(aes(x=as.integer(POs), y=Status, 
               fill = factor(Status)), width = 0.6)  + 
  geom_text(data = subset(vPOTypeStatus_COOP, as.integer(POs) >= 1),
            aes(0, y = Status, label = as.integer(POs)), hjust = 0, size = 3) +
  scale_x_continuous(
    breaks = seq(0, 150, by = 10), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
    position = "bottom"  # Labels are located on the top
  )  +
  facet_wrap(~ paste(Rating, "Ratings"), scales = "free_x", drop = TRUE) +
  theme(legend.position = "bottom") +
  guides(fill=guide_legend(title="Ratings")) +
  xlab("Number of PO Group") + ylab("Status Ratings") + 
  labs(title= "Cooperative PO Type Status with Number of POs", 
       caption="Data Collected by: Junald A. Lagod")  

To display a chart illustrating the records of Farmers Associations (FAs) PO Types along with the corresponding number of POs using the ggplot command in R.
vPOTypeStatus_FA <- vPOTypeStatus %>%
  filter(vPOTypeStatus$Code == "FA")%>%
  group_by(POType, Code, Rating, Status)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vPOTypeStatus_FA) +
  geom_col(aes(x=as.integer(POs), y=Status, 
               fill = factor(Status)), width = 0.6)  + 
  geom_text(data = subset(vPOTypeStatus_FA, as.integer(POs) >= 1),
            aes(0, y = Status, label = as.integer(POs)), hjust = 0, size = 3) +
  scale_x_continuous(
    breaks = seq(0, 150, by = 20), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
    position = "bottom"  # Labels are located on the top
  )  +
  facet_wrap(~ paste(Rating, "Ratings"), scales = "free_x", drop = TRUE) +
  theme(legend.position = "bottom") +
  guides(fill=guide_legend(title="")) +
  xlab("Number of PO Group") + ylab("Status Ratings") + 
  labs(title= "Farmers Associations (FAs) PO Type Status with Number of POs", 
       caption="Data Collected by: Junald A. Lagod")

To display a chart illustrating the records of Irrigators Associations (IAs) PO Types along with the corresponding number of POs using the ggplot command in R.
vPOTypeStatus_IA <- vPOTypeStatus %>%
  filter(vPOTypeStatus$Code == "IA")%>%
  group_by(POType, Code, Rating, Status)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vPOTypeStatus_IA) +
  geom_col(aes(x=as.integer(POs), y=Status, 
               fill = factor(Status)), width = 0.6)  + 
  geom_text(data = subset(vPOTypeStatus_IA, as.integer(POs) >= 1),
            aes(0, y = Status, label = as.integer(POs)), hjust = 0, size = 3) +
  scale_x_continuous(
    breaks = seq(0, 20, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
    position = "bottom"  # Labels are located on the top
  )  +
  facet_wrap(~ paste(Rating, "Ratings"), scales = "free_x", drop = TRUE) +
  theme(legend.position = "bottom") +
  guides(fill=guide_legend(title="")) +
  xlab("Number of PO Group") + ylab("Status Ratings") + 
  labs(title= "Irrigators Associations (IAs) PO Type Status with Number of POs", 
       caption="Data Collected by: Junald A. Lagod")

To display a chart illustrating the records of Water Users Associations (WUAs) PO Types along with the corresponding number of POs using the ggplot command in R.
vPOTypeStatus_WUA <- vPOTypeStatus %>%
  filter(vPOTypeStatus$Code == "WUA")%>%
  group_by(POType, Code, Rating, Status)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vPOTypeStatus_WUA) +
  geom_col(aes(x=as.integer(POs), y=Status, 
               fill = factor(Status)), width = 0.6)  + 
  geom_text(data = subset(vPOTypeStatus_WUA, as.integer(POs) >= 1),
            aes(0, y = Status, label = as.integer(POs)), hjust = 0, size = 3) +
  scale_x_continuous(
    breaks = seq(0, 20, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
    position = "bottom"  # Labels are located on the top
  )  +
  facet_wrap(~ paste(Rating, "Ratings"), scales = "free_x", drop = TRUE) +
  theme(legend.position = "bottom") +
  guides(fill=guide_legend(title="")) +
  xlab("Number of PO Group") + ylab("Status Ratings") + 
  labs(title= "Water Users Associations (WUAs) PO Type Status with Number of POs", 
       caption="Data Collected by: Junald A. Lagod")

To display a chart illustrating the records of Womens Organizations (WOs) PO Types along with the corresponding number of POs using the ggplot command in R.
vPOTypeStatus_WO <- vPOTypeStatus %>%
  filter(vPOTypeStatus$Code == "WO")%>%
  group_by(POType, Code, Rating, Status)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vPOTypeStatus_WO) +
  geom_col(aes(x=as.integer(POs), y=Status, 
               fill = factor(Status)), width = 0.6)  + 
  geom_text(data = subset(vPOTypeStatus_WO, as.integer(POs) >= 1),
            aes(0, y = Status, label = as.integer(POs)), hjust = 0, size = 3) +
  scale_x_continuous(
    breaks = seq(0, 20, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
    position = "bottom"  # Labels are located on the top
  )  +
  facet_wrap(~ paste(Rating, "Ratings"), scales = "free_x", drop = TRUE) +
  theme(legend.position = "bottom") +
  guides(fill=guide_legend(title="")) +
  xlab("Number of PO Group") + ylab("Status Ratings") + 
  labs(title= "Womens Organizations (WOs) PO Type Status with Number of POs", 
       caption="Data Collected by: Junald A. Lagod")

To retrieve a list of covered Regions records along with the corresponding number of Provinces.
This SQL query uses a JOIN operation to combine the Regions table with the Provinces table based on a shared RegionID_FK. It then calculates the count of ProvinceID_PK for each region using the COUNT function and aliases it as ‘Number Of Provinces’. The GROUP BY clause ensures that the count is calculated per region. By executing this query, you will retrieve a result set that includes the Regions records along with the corresponding number of Provinces for each region, you can use the following SQL statement:
vLocations_ARCs <- dbGetQuery(con, 'SELECT
                                          projarea_regions.RegionName AS Region, 
                                          projarea_regions.RegionCode AS RegCode, 
                                          projarea_provinces.ProvinceName AS Province, 
                                          projarea_provinces.ProvinceCode AS ProvCode, 
                                          projarea_settlements.SettlementAreaName AS Settlement, 
                                          projarea_settlements.SettlementAreaCode AS SACode, 
                                          projarea_municipalities.MunicipalityName AS Municipality, 
                                          projarea_municipalities.MunicipalityCode AS MunCode, 
                                          projarea_arcs.ARCName AS ARC, 
                                          Count(projarea_arcs.ARCID_PK) AS ARCs
                                      FROM
                                          (
                                              projarea_regions
                                              INNER JOIN
                                              (
                                                  (
                                                      projarea_provinces
                                                      INNER JOIN
                                                      projarea_settlements
                                                      ON 
                                                          projarea_provinces.ProvinceID_PK 
                                                          = projarea_settlements.ProvinceID_FK
                                                  )
                                                  LEFT JOIN
                                                  projarea_municipalities
                                                  ON 
                                                      projarea_settlements.SettlementID_PK 
                                                      = projarea_municipalities.SettlementID_FK
                                              )
                                              ON 
                                                  projarea_regions.RegionID_PK 
                                                  = projarea_provinces.RegionID_FK
                                          )
                                          LEFT JOIN
                                          projarea_arcs
                                          ON 
                                              projarea_municipalities.MunicipalityID_PK 
                                              = projarea_arcs.MunicipalityID_FK
                                      GROUP BY
                                          projarea_regions.RegionCode, 
                                          projarea_regions.RegionName, 
                                          projarea_provinces.ProvinceName, 
                                          projarea_provinces.ProvinceCode, 
                                          projarea_settlements.SettlementAreaCode, 
                                          projarea_settlements.SettlementAreaName, 
                                          projarea_municipalities.MunicipalityName, 
                                          projarea_municipalities.MunicipalityCode,
                                          projarea_arcs.ARCName
                                      ORDER BY
                                          projarea_regions.RegionCode ASC, 
                                          projarea_provinces.ProvinceCode ASC, 
                                          projarea_settlements.SettlementAreaCode ASC, 
                                          projarea_municipalities.MunicipalityName ASC;')

vLocations_BRGYS <- dbGetQuery(con, 'SELECT
                                          projarea_regions.RegionName AS Region, 
                                          projarea_regions.RegionCode AS RegCode, 
                                          projarea_provinces.ProvinceName AS Province, 
                                          projarea_provinces.ProvinceCode AS ProvCode, 
                                          projarea_settlements.SettlementAreaName AS Settlement, 
                                          projarea_settlements.SettlementAreaCode AS SACode, 
                                          projarea_municipalities.MunicipalityName AS Municipality, 
                                          projarea_municipalities.MunicipalityCode AS MunCode,
                                          projarea_barangays.BarangayName AS Barangay,
                                          Count(projarea_barangays.BarangayID_PK) AS Barangays
                                      FROM
                                          (
                                              projarea_regions
                                              INNER JOIN
                                              (
                                                  (
                                                      projarea_provinces
                                                      INNER JOIN
                                                      projarea_settlements
                                                      ON 
                                                          projarea_provinces.ProvinceID_PK 
                                                          = projarea_settlements.ProvinceID_FK
                                                  )
                                                  LEFT JOIN
                                                  projarea_municipalities
                                                  ON 
                                                      projarea_settlements.SettlementID_PK 
                                                      = projarea_municipalities.SettlementID_FK
                                              )
                                              ON 
                                                  projarea_regions.RegionID_PK 
                                                  = projarea_provinces.RegionID_FK
                                          )
                                          LEFT JOIN
                                          projarea_barangays
                                          ON 
                                              projarea_municipalities.MunicipalityID_PK 
                                              = projarea_barangays.MunicipalityID_FK
                                      GROUP BY
                                          projarea_regions.RegionCode, 
                                          projarea_regions.RegionName, 
                                          projarea_provinces.ProvinceName, 
                                          projarea_provinces.ProvinceCode, 
                                          projarea_settlements.SettlementAreaCode, 
                                          projarea_settlements.SettlementAreaName, 
                                          projarea_municipalities.MunicipalityName, 
                                          projarea_municipalities.MunicipalityCode,
                                          projarea_barangays.BarangayName
                                      ORDER BY
                                          projarea_regions.RegionCode ASC, 
                                          projarea_provinces.ProvinceCode ASC, 
                                          projarea_settlements.SettlementAreaCode ASC, 
                                          projarea_municipalities.MunicipalityName ASC;')

vLocations_ARCs_tmp <- vLocations_ARCs %>%
  select(-ARC) 
vLocations_BRGYS_tmp <- vLocations_BRGYS %>%
  select(-Barangay)
To view the Regions table within the database, you can follow the command below:
vLocREGIONS_tmp <- vLocations_BRGYS_tmp %>%
  group_by(Region, RegCode)  %>%
  count(Province) %>%
  summarise(Provinces = n(), .groups = 'drop')

# Make dataframe
results_df <- data.frame(vLocREGIONS_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("Region", "Code", "No. of Provinces", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Covered Regions table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Covered Regions table
Region Code No. of Provinces
Region X R10 2
Region XI R11 2
Region XII R12 3
Total: 7
To display a chart illustrating the records of Regions along with the corresponding number of Provinces using the ggplot command in R.
ggplot(vLocREGIONS_tmp, aes(x="", y= as.integer(Provinces), fill=Region)) +
  geom_col(show.legend = TRUE) +
  geom_text(aes(label = as.integer(Provinces)), 
    position = position_stack(vjust = 0.5), show.legend = FALSE) +
    coord_polar(theta = "y") +
    scale_fill_manual(values = c("#EC754A", "#FFF123", "#ABC123")) +
    theme(legend.position = "right") +
    guides(fill=guide_legend(title="Regions"))  +
    xlab("Number of Provinces") + ylab("Number of Provinces")  +
    labs(title= "Covered Regions with Number of Provinces",  
         caption="Data Collected by: Junald A. Lagod")

To retrieve a list of covered Regions and PO Types records along with the corresponding number of Provinces.
vLocations_POTypes <- dbGetQuery(con, 'SELECT
                                          projarea_regions.RegionName AS "Region", 
                                          projarea_provinces.ProvinceName AS "Province", 
                                          projarea_settlements.SettlementAreaName AS "SettlementArea", 
                                          projarea_municipalities.MunicipalityName AS "Municipality", 
                                          projarea_barangays.BarangayName AS "Barangay", 
                                          subcomponents.SubComponentName AS "POType",
                                          subcomponents.SubComponentCode AS "Code", 
                                          COUNT(pogroup.POID_PK) AS POs,
                                          SUM(pogroup.ARBMale ) AS ARBMale,
                                          SUM(pogroup.ARBFemale ) AS ARBFemale,
                                          SUM(pogroup.NonARBMale ) AS NonARBMale,
                                          SUM(pogroup.NonARBFemale ) AS NonARBFemale,
                                          SUM(pogroup.IPMale ) AS IPMale,
                                          SUM(pogroup.IPFemale ) AS IPFemale,
                                          SUM(pogroup.NonIPMale ) AS NonIPMale,
                                          SUM(pogroup.NonIPFemale ) AS NonIPFemale
                                      FROM
                                          projarea_regions
                                          JOIN
                                          projarea_provinces
                                          ON 
                                              projarea_regions.RegionID_PK 
                                              = projarea_provinces.RegionID_FK
                                          INNER JOIN
                                          projarea_settlements
                                          ON 
                                              projarea_provinces.ProvinceID_PK 
                                              = projarea_settlements.ProvinceID_FK
                                          INNER JOIN
                                          projarea_municipalities
                                          ON 
                                              projarea_settlements.SettlementID_PK 
                                              = projarea_municipalities.SettlementID_FK
                                          INNER JOIN
                                          projarea_barangays
                                          ON 
                                              projarea_municipalities.MunicipalityID_PK 
                                              = projarea_barangays.MunicipalityID_FK
                                          INNER JOIN
                                          pogroup
                                          ON 
                                              projarea_barangays.BarangayID_PK = pogroup.BarangayID_FK
                                          INNER JOIN
                                          subcomponents
                                          ON 
                                              pogroup.POTypeID_FK = subcomponents.SubComponentID_PK
                                      GROUP BY
                                          projarea_regions.RegionName, 
                                          projarea_provinces.ProvinceName, 
                                          projarea_settlements.SettlementAreaName, 
                                          projarea_municipalities.MunicipalityName, 
                                          projarea_barangays.BarangayName, 
                                          subcomponents.SubComponentName,
                                          subcomponents.SubComponentCode
                                      ORDER BY
                                          projarea_regions.RegionName ASC, 
                                          projarea_provinces.ProvinceName ASC, 
                                          projarea_settlements.SettlementAreaName ASC, 
                                          projarea_municipalities.MunicipalityName ASC, 
                                          projarea_barangays.BarangayName ASC, 
                                          subcomponents.SubComponentName ASC,
                                          subcomponents.SubComponentCode ASC;')

vLocations_SPTypes <- dbGetQuery(con, 'SELECT
                                            projarea_regions.RegionName AS Region, 
                                            projarea_provinces.ProvinceName AS Province, 
                                            projarea_settlements.SettlementAreaName AS SettlementArea, 
                                            projarea_municipalities.MunicipalityName AS Municipality, 
                                            projarea_barangays.BarangayName AS Barangay, 
                                            subcomponents.SubComponentName AS SPType, 
                                            subcomponents.SubComponentCode AS `Code`,
                                            COUNT(subprojects.SPID_PK) AS SPs, 
                                            SUM(subprojects.Ben) AS Beneficiaries, 
                                            SUM(subprojects.Qty) AS Qty,
                                            (CASE 
                                                    WHEN subcomponents.SubComponentCode = "AGBiz" THEN "Has"
                                                    WHEN subcomponents.SubComponentCode = "AGRI" THEN "Has"
                                                    WHEN subcomponents.SubComponentCode = "AGRO" THEN "Has"
                                                    WHEN subcomponents.SubComponentCode = "CI" THEN "Has"
                                                    WHEN subcomponents.SubComponentCode = "BRDG" THEN "Lms"
                                                    WHEN subcomponents.SubComponentCode = "FMR" THEN "Kms"
                                                    WHEN subcomponents.SubComponentCode = "IRRIG" THEN "Has"
                                                    WHEN subcomponents.SubComponentCode = "PHF" THEN "Units"
                                                    WHEN subcomponents.SubComponentCode = "RWS" THEN "HHs"
                                            END) AS UnitMeasure
                                        FROM
                                            projarea_regions
                                            JOIN
                                            projarea_provinces
                                            ON 
                                                projarea_regions.RegionID_PK = projarea_provinces.RegionID_FK
                                            INNER JOIN
                                            projarea_settlements
                                            ON 
                                                projarea_provinces.ProvinceID_PK = projarea_settlements.ProvinceID_FK
                                            INNER JOIN
                                            projarea_municipalities
                                            ON 
                                                projarea_settlements.SettlementID_PK = projarea_municipalities.SettlementID_FK
                                            INNER JOIN
                                            projarea_barangays
                                            ON 
                                                projarea_municipalities.MunicipalityID_PK = projarea_barangays.MunicipalityID_FK
                                            INNER JOIN
                                            subcomponents
                                            INNER JOIN
                                            subprojects
                                            ON 
                                                projarea_barangays.BarangayID_PK = subprojects.BarangayID_FK AND
                                                subcomponents.SubComponentID_PK = subprojects.SPTypeID_FK
                                        GROUP BY
                                            projarea_regions.RegionName, 
                                            projarea_provinces.ProvinceName, 
                                            projarea_settlements.SettlementAreaName, 
                                            projarea_municipalities.MunicipalityName, 
                                            projarea_barangays.BarangayName, 
                                            subcomponents.SubComponentName, 
                                            subcomponents.SubComponentCode
                                        ORDER BY
                                            projarea_regions.RegionName ASC, 
                                            projarea_provinces.ProvinceName ASC, 
                                            projarea_settlements.SettlementAreaName ASC, 
                                            projarea_municipalities.MunicipalityName ASC, 
                                            projarea_barangays.BarangayName ASC, 
                                            subcomponents.SubComponentName ASC, 
                                            subcomponents.SubComponentCode ASC;')
To view the Regions with SP Types table within the database, you can follow the command below:
#Region X
# Make dataframe
vRegion <- "Region X"

vRegionX_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Province, -SettlementArea, -Municipality, -Barangay)

vRegionX_SPTypes_tmp <- vRegionX_SPTypes_tmp %>%
  filter(vRegionX_SPTypes_tmp$Region == vRegion)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vRegionX_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Region X with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 24 3462 3352.36
Agro-forestry AGRO Has 16 745 4076.71
Bridge BRDG Lms 8 0 581.00
Crop Intensification CI Has 2 NA 300.00
Farm to Market Road FMR Kms 11 0 65.93
Irrigation IRRIG Has 7 0 575.00
Post Harvest Facilities PHF Units 22 NA 31.00
Rural Water Systems RWS HHs 8 0 1910.00
Total: 98 NA 10892.00
#Region XI
# Make dataframe
vRegion <- "Region XI"

vRegionXI_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Province, -SettlementArea, -Municipality, -Barangay) 

vRegionXI_SPTypes_tmp <- vRegionXI_SPTypes_tmp %>%
  filter(vRegionXI_SPTypes_tmp$Region == vRegion)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vRegionXI_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Region XI with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 12 1931 1867.05
Agro-forestry AGRO Has 2 74 408.90
Bridge BRDG Lms 2 0 55.00
Crop Intensification CI Has 4 NA 949.00
Farm to Market Road FMR Kms 6 0 34.66
Irrigation IRRIG Has 1 0 106.00
Post Harvest Facilities PHF Units 8 NA 12.00
Rural Water Systems RWS HHs 7 0 1886.00
Total: 42 NA 5318.61
#Region XII
# Make dataframe
vRegion <- "Region XII"

vRegionXII_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Province, -SettlementArea, -Municipality, -Barangay) 

vRegionXII_SPTypes_tmp <- vRegionXII_SPTypes_tmp %>%
  filter(vRegionXII_SPTypes_tmp$Region == vRegion)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vRegionXII_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Region XII with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 29 6607 6400.562
Agro-forestry AGRO Has 17 492 2692.166
Bridge BRDG Lms 5 0 141.000
Crop Intensification CI Has 16 NA 3977.000
Farm to Market Road FMR Kms 23 NA 139.622
Irrigation IRRIG Has 11 0 1249.330
Post Harvest Facilities PHF Units 35 NA 45.000
Rural Water Systems RWS HHs 11 NA 3281.000
Total: 147 NA 17925.681
To display a chart illustrating the records of Regions along with the corresponding number of SPs using the ggplot command in R.
vRegions_SPTypes_tmp <- vLocations_SPTypes %>%
  group_by(Region, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vRegions_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +
  scale_y_continuous(
    breaks = seq(0, 50, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~ Region, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vRegions_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= "Covered Regions and SP Types with No. of Sub-Projects (SPs)",  
       caption="Data Collected by: Junald A. Lagod")

To view the Regions with PO Types table within the database, you can follow the command below:
#Region X
# Make dataframe
vRegionX_POTypes_tmp <- vLocations_POTypes %>%
  select(-Province, -SettlementArea, -Municipality, -Barangay) %>%
  drop_na()

vRegionX_POTypes_tmp <- vRegionX_POTypes_tmp %>%
  filter(vRegionX_POTypes_tmp$Region == "Region X")  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), 
            ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vRegionX_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", 
                       "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", 
                       "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Region X with PO Types table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Region X with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 38 839 773 106 364 15 22 5 3
Farmers Association FA 19 438 181 87 46 0 0 0 0
Irrigators Association IA 5 88 30 72 20 0 0 0 0
Water Users Association WUA 10 505 243 5 0 0 0 0 0
Womens Organization WO 3 0 41 0 30 0 0 0 0
Total: 75 1870 1268 270 460 15 22 5 3
#Region XI
# Make dataframe
vRegionXI_POTypes_tmp <- vLocations_POTypes %>%
  select(-Province, -SettlementArea, -Municipality, -Barangay) %>%
  drop_na()

vRegionXI_POTypes_tmp <- vRegionXI_POTypes_tmp %>%
  filter(vRegionXI_POTypes_tmp$Region == "Region XI")  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), 
            ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vRegionXI_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Region XI with PO Types table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Region XI with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 7 119 157 115 129 61 54 1 0
Farmers Association FA 29 1655 595 507 318 1052 472 80 16
Irrigators Association IA 2 103 35 0 0 103 35 0 0
Water Users Association WUA 7 539 544 306 132 663 478 218 89
Total: 45 2416 1331 928 579 1879 1039 299 105
#Region XII
# Make dataframe
vRegionXII_POTypes_tmp <- vLocations_POTypes %>%
  select(-Province, -SettlementArea, -Municipality, -Barangay) %>%
  drop_na()

vRegionXII_POTypes_tmp <- vRegionXII_POTypes_tmp %>%
  filter(vRegionXII_POTypes_tmp$Region == "Region XII")  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), 
            ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vRegionXII_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Region XII with PO Types table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Region XII with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 23 1798 1952 860 1349 12 0 1663 2473
Farmers Association FA 158 3222 2301 389 878 399 201 2144 1739
Irrigators Association IA 14 353 103 0 0 0 0 144 61
Water Users Association WUA 14 460 285 129 78 98 42 374 212
Womens Organization WO 20 0 830 0 132 0 63 0 461
Total: 229 5833 5471 1378 2437 509 306 4325 4946
To display a chart illustrating the records of Regions along with the corresponding number of POs using the ggplot command in R.
vRegions_POTypes_tmp <- vLocations_POTypes %>%
  group_by(Region, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vRegions_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 200, by = 20), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~ Region, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vRegions_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= "Covered Regions and PO Types with Number of PO Group",  
       caption="Data Collected by: Junald A. Lagod")

To view the Provinces in Region X with SP Types table within the database, you can follow the command below:
#Bukidnon, Region X
# Make dataframe
vRegion <- "Region X"
vProvince <- "Bukidnon"

vRegX_BUK_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-SettlementArea, -Municipality, -Barangay)

vRegX_BUK_SPTypes_tmp <- vRegX_BUK_SPTypes_tmp %>%
  filter(vRegX_BUK_SPTypes_tmp$Region == vRegion, 
         vRegX_BUK_SPTypes_tmp$Province == vProvince)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vRegX_BUK_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Bukidnon Region X with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 6 501 485.2685
Bridge BRDG Lms 1 0 18.0000
Crop Intensification CI Has 2 NA 300.0000
Farm to Market Road FMR Kms 3 0 12.6300
Irrigation IRRIG Has 3 0 265.0000
Post Harvest Facilities PHF Units 9 NA 11.0000
Rural Water Systems RWS HHs 1 0 212.0000
Total: 25 NA 1303.8985
#Lanao del Norte, Region X
# Make dataframe
vRegion <- "Region X"
vProvince <- "Lanao del Norte"

vRegX_LDN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-SettlementArea, -Municipality, -Barangay)

vRegX_LDN_SPTypes_tmp <- vRegX_LDN_SPTypes_tmp %>%
  filter(vRegX_LDN_SPTypes_tmp$Region == vRegion, 
         vRegX_LDN_SPTypes_tmp$Province == vProvince)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vRegX_LDN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Lanao del Norte Region X with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 18 2961 2867.091
Agro-forestry AGRO Has 16 745 4076.710
Bridge BRDG Lms 7 0 563.000
Farm to Market Road FMR Kms 8 0 53.300
Irrigation IRRIG Has 4 0 310.000
Post Harvest Facilities PHF Units 13 NA 20.000
Rural Water Systems RWS HHs 7 0 1698.000
Total: 73 NA 9588.101
To display a chart illustrating the records of Region X along with the corresponding number of SPs using the ggplot command in R.
vRegionX_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion)  %>%
  group_by(Province, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vRegionX_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~ Province, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vRegionX_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Covered Provinces in", vRegion, "and SP Types w/ No. of Sub-Projects (SPs)"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Provinces in Region X with PO Types table within the database, you can follow the command below:
# Make dataframe
#Bukidnon
# Make dataframe
vProvince <- "Bukidnon"

vRegX_BUK_POTypes_tmp <- vLocations_POTypes %>%
  select(-SettlementArea, -Municipality, -Barangay) %>%
  drop_na()

vRegX_BUK_POTypes_tmp <- vRegX_BUK_POTypes_tmp %>%
  filter(vRegX_BUK_POTypes_tmp$Region == vRegion, vRegX_BUK_POTypes_tmp$Province == vProvince)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vRegX_BUK_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vProvince, vRegion, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Bukidnon Region X with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 2 123 30 4 104 0 0 0 0
Farmers Association FA 3 32 9 50 31 0 0 0 0
Irrigators Association IA 1 19 7 55 13 0 0 0 0
Water Users Association WUA 1 149 56 5 0 0 0 0 0
Womens Organization WO 1 0 16 0 30 0 0 0 0
Total: 8 323 118 114 178 0 0 0 0
#Lanao del Norte
# Make dataframe
vProvince <- "Lanao del Norte"

vRegX_LDN_POTypes_tmp <- vLocations_POTypes %>%
  select(-SettlementArea, -Municipality, -Barangay) %>%
  drop_na()

vRegX_LDN_POTypes_tmp <- vRegX_LDN_POTypes_tmp %>%
  filter(vRegX_LDN_POTypes_tmp$Region == vRegion, vRegX_LDN_POTypes_tmp$Province == vProvince)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vRegX_LDN_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vProvince, vRegion, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Lanao del Norte Region X with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 36 716 743 102 260 15 22 5 3
Farmers Association FA 16 406 172 37 15 0 0 0 0
Irrigators Association IA 4 69 23 17 7 0 0 0 0
Water Users Association WUA 9 356 187 0 0 0 0 0 0
Womens Organization WO 2 0 25 0 0 0 0 0 0
Total: 67 1547 1150 156 282 15 22 5 3
To display a chart illustrating the records of Provinces in Region along with the corresponding number of POs using the ggplot command in R.
vRegionX_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion)  %>%
  group_by(Province, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vRegionX_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 50, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Province, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vLocations_POTypes) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Covered Provinces in", vRegion, "and PO Types with No. of PO Group"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Provinces in Region XI with SP Types table within the database, you can follow the command below:
#Davao de Oro, Region XI
# Make dataframe
vRegion <- "Region XI"
vProvince <- "Davao de Oro"

vRegXI_DDO_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-SettlementArea, -Municipality, -Barangay)

vRegXI_DDO_SPTypes_tmp <- vRegXI_DDO_SPTypes_tmp %>%
  filter(vRegXI_DDO_SPTypes_tmp$Region == vRegion, 
         vRegXI_DDO_SPTypes_tmp$Province == vProvince)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vRegXI_DDO_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Davao de Oro Region XI with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 5 869 840.76
Agro-forestry AGRO Has 2 74 408.90
Crop Intensification CI Has 2 NA 475.00
Farm to Market Road FMR Kms 2 0 16.07
Irrigation IRRIG Has 1 0 106.00
Post Harvest Facilities PHF Units 3 NA 6.00
Rural Water Systems RWS HHs 3 0 629.00
Total: 18 NA 2481.73
#Davao del Sur, Region XI
# Make dataframe
vProvince <- "Davao del Sur"

vRegXI_DDS_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-SettlementArea, -Municipality, -Barangay)

vRegXI_DDS_SPTypes_tmp <- vRegXI_DDS_SPTypes_tmp %>%
  filter(vRegXI_DDS_SPTypes_tmp$Region == vRegion, 
         vRegXI_DDS_SPTypes_tmp$Province == vProvince)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vRegXI_DDS_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Davao del Sur Region XI with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 7 1062 1026.29
Bridge BRDG Lms 2 0 55.00
Crop Intensification CI Has 2 NA 474.00
Farm to Market Road FMR Kms 4 0 18.59
Post Harvest Facilities PHF Units 5 NA 6.00
Rural Water Systems RWS HHs 4 0 1257.00
Total: 24 NA 2836.88
To display a chart illustrating the records of Region XI along with the corresponding number of SPs using the ggplot command in R.
vRegionXI_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion)  %>%
  group_by(Province, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vRegionXI_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~ Province, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vRegionX_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Covered Provinces in", vRegion, "and SP Types w/ No. of Sub-Projects (SPs)"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Region XI Provinces table within the database, you can follow the command below:
#Davao de Oro
# Make dataframe
vProvince <- "Davao de Oro"

vRegXI_DDO_POTypes_tmp <- vLocations_POTypes %>%
  select(-SettlementArea, -Municipality, -Barangay) %>%
  drop_na()

vRegXI_DDO_POTypes_tmp <- vRegXI_DDO_POTypes_tmp %>%
  filter(vRegXI_DDO_POTypes_tmp$Region == vRegion, vRegXI_DDO_POTypes_tmp$Province == vProvince)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vRegXI_DDO_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vProvince, vRegion, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Davao de Oro Region XI with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 4 60 54 2 0 61 54 1 0
Farmers Association FA 2 650 324 0 0 650 324 0 0
Irrigators Association IA 2 103 35 0 0 103 35 0 0
Water Users Association WUA 3 515 394 0 0 515 394 0 0
Total: 11 1328 807 2 0 1329 807 1 0
#Davao del Sur
# Make dataframe
vProvince <- "Davao del Sur"

vRegXI_DDS_POTypes_tmp <- vLocations_POTypes %>%
  select(-SettlementArea, -Municipality, -Barangay) %>%
  drop_na()

vRegXI_DDS_POTypes_tmp <- vRegXI_DDS_POTypes_tmp %>%
  filter(vRegXI_DDS_POTypes_tmp$Region == vRegion, vRegXI_DDS_POTypes_tmp$Province == vProvince)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vRegXI_DDS_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vProvince, vRegion, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Davao del Sur Region XI with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 3 59 103 113 129 0 0 0 0
Farmers Association FA 27 1005 271 507 318 402 148 80 16
Water Users Association WUA 4 24 150 306 132 148 84 218 89
Total: 34 1088 524 926 579 550 232 298 105
To display a chart illustrating the records of Provinces in Region XI along with the corresponding number of POs using the ggplot command in R.
vRegionXI_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion)  %>%
  group_by(Province, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vRegionXI_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Province, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vLocations_POTypes) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Covered Provinces in",  vRegion, "and PO Types with No. of PO Group"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Provinces in Region XII with SP Types table within the database, you can follow the command below:
#North Cotabato, Region XII
# Make dataframe
vRegion <- "Region XII"
vProvince <- "North Cotabato"

vRegXII_NC_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-SettlementArea, -Municipality, -Barangay)

vRegXII_NC_SPTypes_tmp <- vRegXII_NC_SPTypes_tmp %>%
  filter(vRegXII_NC_SPTypes_tmp$Region == vRegion, 
         vRegXII_NC_SPTypes_tmp$Province == vProvince)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vRegXII_NC_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
North Cotabato Region XII with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 18 4682 4534.564
Agro-forestry AGRO Has 9 203 1102.385
Bridge BRDG Lms 2 0 54.000
Crop Intensification CI Has 6 NA 1407.000
Farm to Market Road FMR Kms 13 NA 80.322
Irrigation IRRIG Has 4 0 450.330
Post Harvest Facilities PHF Units 14 NA 18.000
Rural Water Systems RWS HHs 6 0 1771.000
Total: 72 NA 9417.600
#South Cotabato, Region XII
# Make dataframe
vProvince <- "South Cotabato"

vRegXII_SC_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-SettlementArea, -Municipality, -Barangay)

vRegXII_SC_SPTypes_tmp <- vRegXII_SC_SPTypes_tmp %>%
  filter(vRegXII_SC_SPTypes_tmp$Region == vRegion, 
         vRegXII_SC_SPTypes_tmp$Province == vProvince)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vRegXII_SC_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
South Cotabato Region XII with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 4 349 337.8100
Agro-forestry AGRO Has 2 78 425.2482
Bridge BRDG Lms 2 0 27.0000
Crop Intensification CI Has 1 NA 810.0000
Farm to Market Road FMR Kms 4 0 22.2900
Irrigation IRRIG Has 3 0 106.0000
Post Harvest Facilities PHF Units 6 NA 8.0000
Rural Water Systems RWS HHs 2 0 210.0000
Total: 24 NA 1946.3482
#Sultan Kudarat, Region XII
# Make dataframe
vRegion <- "Region XII"
vProvince <- "Sultan Kudarat"

vRegXII_SK_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-SettlementArea, -Municipality, -Barangay)

vRegXII_SK_SPTypes_tmp <- vRegXII_SK_SPTypes_tmp %>%
  filter(vRegXII_SK_SPTypes_tmp$Region == vRegion, 
         vRegXII_SK_SPTypes_tmp$Province == vProvince)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vRegXII_SK_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Sultan Kudarat Region XII with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 7 1576 1528.189
Agro-forestry AGRO Has 6 211 1164.533
Bridge BRDG Lms 1 0 60.000
Crop Intensification CI Has 9 NA 1760.000
Farm to Market Road FMR Kms 6 0 37.010
Irrigation IRRIG Has 4 0 693.000
Post Harvest Facilities PHF Units 15 NA 19.000
Rural Water Systems RWS HHs 3 NA 1300.000
Total: 51 NA 6561.732
To display a chart illustrating the records of Region XII along with the corresponding number of SPs using the ggplot command in R.
vRegionXII_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion)  %>%
  group_by(Province, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vRegionXII_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~ Province, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vRegionX_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Covered Provinces in", vRegion, "and SP Types w/ No. of Sub-Projects (SPs)"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Region XII Provinces table within the database, you can follow the command below:
#North Cotabato
# Make dataframe
vProvince <- "North Cotabato"

vRegXII_NC_POTypes_tmp <- vLocations_POTypes %>%
  select(-SettlementArea, -Municipality, -Barangay) %>%
  drop_na()

vRegXII_NC_POTypes_tmp <- vRegXII_NC_POTypes_tmp %>%
  filter(vRegXII_NC_POTypes_tmp$Region == vRegion, vRegXII_NC_POTypes_tmp$Province == vProvince)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vRegXII_NC_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "North Cotabato, Region XII with PO Types table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
North Cotabato, Region XII with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 11 923 1206 740 1267 0 0 1663 2473
Farmers Association FA 118 2134 1893 172 800 388 200 1845 1725
Irrigators Association IA 6 144 61 0 0 0 0 144 61
Water Users Association WUA 9 357 203 109 49 95 41 371 211
Womens Organization WO 12 0 382 0 16 0 63 0 461
Total: 156 3558 3745 1021 2132 483 304 4023 4931
#South Cotabato
# Make dataframe
vProvince <- "South Cotabato"

vRegXII_SC_POTypes_tmp <- vLocations_POTypes %>%
  select(-SettlementArea, -Municipality, -Barangay) %>%
  drop_na()

vRegXII_SC_POTypes_tmp <- vRegXII_SC_POTypes_tmp %>%
  filter(vRegXII_SC_POTypes_tmp$Region == vRegion, vRegXII_SC_POTypes_tmp$Province == vProvince)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vRegXII_SC_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "South Cotabato, Region XII with PO Types table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
South Cotabato, Region XII with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 6 292 218 109 72 12 0 0 0
Irrigators Association IA 3 0 0 0 0 0 0 0 0
Water Users Association WUA 2 31 25 20 29 3 1 3 1
Total: 11 323 243 129 101 15 1 3 1
#Sultan Kudarat
# Make dataframe
vProvince <- "Sultan Kudarat"

vRegXII_SK_POTypes_tmp <- vLocations_POTypes %>%
  select(-SettlementArea, -Municipality, -Barangay) %>%
  drop_na()

vRegXII_SK_POTypes_tmp <- vRegXII_SK_POTypes_tmp %>%
  filter(vRegXII_SK_POTypes_tmp$Region == vRegion, vRegXII_SK_POTypes_tmp$Province == vProvince)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vRegXII_SK_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Sultan Kudarat, Region XII with PO Types table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Sultan Kudarat, Region XII with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 6 583 528 11 10 0 0 0 0
Farmers Association FA 40 1088 408 217 78 11 1 299 14
Irrigators Association IA 5 209 42 0 0 0 0 0 0
Water Users Association WUA 3 72 57 0 0 0 0 0 0
Womens Organization WO 8 0 448 0 116 0 0 0 0
Total: 62 1952 1483 228 204 11 1 299 14
To display a chart illustrating the records of Provinces in Region XII along with the corresponding number of POs using the ggplot command in R.
vRegionXII_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == "Region XII")  %>%
  group_by(Province, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vRegionXII_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 200, by = 10), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Province, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vLocations_POTypes) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= "Covered Provinces in Region XII and PO Types with No. of PO Group", 
       caption="Data Collected by: Junald A. Lagod")

To retrieve a list of covered Provines records along with the corresponding number of Settlements
To view the Province table within the database, you can follow the command below:
vLocPROVINCES_tmp <- vLocations_BRGYS_tmp %>%
  group_by(Region, Province, ProvCode)  %>%
  count(Settlement) %>%
  summarise(Settlements = n(), .groups = 'drop')

# Make dataframe
results_df <- data.frame(vLocPROVINCES_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("Region", "Province", "Code", "No. of Settlements", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Covered Provinces table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Covered Provinces table
Region Province Code No. of Settlements
Region X Bukidnon BUK 1
Region X Lanao del Norte LDN 3
Region XI Davao de Oro DDO 1
Region XI Davao del Sur DDS 1
Region XII North Cotabato NC 3
Region XII South Cotabato SC 1
Region XII Sultan Kudarat SK 2
Total: 12
To display a chart illustrating the records of Provinces along with the corresponding number of Settlements using the ggplot command in R.
ggplot(vLocPROVINCES_tmp, aes(x = ProvCode, y = as.integer(Settlements), fill=Province)) +
  geom_col() +
  geom_text(aes(label = as.integer(Settlements), y = as.integer(Settlements) / 2)) +
  scale_y_continuous(
    breaks = seq(0, 10, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="Provinces")) + 
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~ Region, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vLocPROVINCES_tmp) + 
  xlab("Provinces") + ylab("Number of Settlements")  +
  labs(title= "Covered Provinces with Number of Settlements",  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Bukidnon, Region X with SP Types table within the database, you can follow the command below:
vRegion <- "Region X"
vProvince <- "Bukidnon"
vSettlementArea <- "Kadingilan Settlement Area"

vKAD_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Municipality, -Barangay)

vKAD_SA_SPTypes_tmp <- vKAD_SA_SPTypes_tmp %>%
  filter(vKAD_SA_SPTypes_tmp$Region == vRegion, 
         vKAD_SA_SPTypes_tmp$Province == vProvince,
         vKAD_SA_SPTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vKAD_SA_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Bukidnon Region X with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 6 501 485.2685
Bridge BRDG Lms 1 0 18.0000
Crop Intensification CI Has 2 NA 300.0000
Farm to Market Road FMR Kms 3 0 12.6300
Irrigation IRRIG Has 3 0 265.0000
Post Harvest Facilities PHF Units 9 NA 11.0000
Rural Water Systems RWS HHs 1 0 212.0000
Total: 25 NA 1303.8985
To display a chart illustrating the records of Settlement Areas in Bukidnon, Region X along with the corresponding number of SPs using the ggplot command in R.
vKAD_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince,
         vLocations_SPTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Province, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vKAD_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~ Province, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vRegionX_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Settlement Areas in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Bukidnon, Region X table within the database, you can follow the command below:
#Kadingilan Settlement Area
# Make dataframe
vKAD_SA_POTypes_tmp <- vLocations_POTypes %>%
  select(-Municipality, -Barangay) %>%
  drop_na()

vKAD_SA_POTypes_tmp <- vKAD_SA_POTypes_tmp %>%
  filter(vKAD_SA_POTypes_tmp$Region == vRegion, 
         vKAD_SA_POTypes_tmp$Province == vProvince,
         vKAD_SA_POTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vKAD_SA_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Kadingilan Settlement Area, Bukidnon with PO Types table", 
      booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Kadingilan Settlement Area, Bukidnon with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 2 123 30 4 104 0 0 0 0
Farmers Association FA 3 32 9 50 31 0 0 0 0
Irrigators Association IA 1 19 7 55 13 0 0 0 0
Water Users Association WUA 1 149 56 5 0 0 0 0 0
Womens Organization WO 1 0 16 0 30 0 0 0 0
Total: 8 323 118 114 178 0 0 0 0
To display a chart illustrating the records of Provinces in Region X along with the corresponding number of POs using the ggplot command in R.
vSA_KAD_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == "Region X", 
         vLocations_POTypes$Province == "Bukidnon")  %>%
  group_by(SettlementArea, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vSA_KAD_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 10, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~SettlementArea, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vLocations_POTypes) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= "Settlement Areas in Bukidnon, Region X and PO Types with No. of PO Group", 
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Lanao del Norte, Region X with SP Types table within the database, you can follow the command below:
vRegion <- "Region X"
vProvince <- "Lanao del Norte"
vSettlementArea <- "Lanao del Norte Settlement Area 1"

vLDN_SA1_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Municipality, -Barangay)

vLDN_SA1_SPTypes_tmp <- vLDN_SA1_SPTypes_tmp %>%
  filter(vLDN_SA1_SPTypes_tmp$Region == vRegion, 
         vLDN_SA1_SPTypes_tmp$Province == vProvince,
         vLDN_SA1_SPTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vLDN_SA1_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Lanao del Norte Settlement Area 1 in Lanao del Norte Region X with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 12 1770 1714.251
Agro-forestry AGRO Has 11 480 2625.117
Bridge BRDG Lms 4 0 178.000
Farm to Market Road FMR Kms 7 0 51.320
Irrigation IRRIG Has 3 0 190.000
Post Harvest Facilities PHF Units 9 NA 14.000
Rural Water Systems RWS HHs 6 0 1508.000
Total: 52 NA 6280.688
vSettlementArea <- "Lanao del Norte Settlement Area 2"

vLDN_SA2_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Municipality, -Barangay)

vLDN_SA2_SPTypes_tmp <- vLDN_SA2_SPTypes_tmp %>%
  filter(vLDN_SA2_SPTypes_tmp$Region == vRegion, 
         vLDN_SA2_SPTypes_tmp$Province == vProvince,
         vLDN_SA2_SPTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vLDN_SA2_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Lanao del Norte Settlement Area 2 in Lanao del Norte Region X with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 3 471 455.77
Agro-forestry AGRO Has 2 112 613.35
Bridge BRDG Lms 3 0 385.00
Farm to Market Road FMR Kms 1 0 1.98
Irrigation IRRIG Has 1 0 120.00
Post Harvest Facilities PHF Units 1 NA 2.00
Total: 11 NA 1578.10
vSettlementArea <- "Lanao del Norte Settlement Area 3"

vLDN_SA3_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Municipality, -Barangay)

vLDN_SA3_SPTypes_tmp <- vLDN_SA3_SPTypes_tmp %>%
  filter(vLDN_SA3_SPTypes_tmp$Region == vRegion, 
         vLDN_SA3_SPTypes_tmp$Province == vProvince,
         vLDN_SA3_SPTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vLDN_SA3_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Lanao del Norte Settlement Area 3 in Lanao del Norte Region X with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 3 720 697.0703
Agro-forestry AGRO Has 3 153 838.2431
Post Harvest Facilities PHF Units 3 0 4.0000
Rural Water Systems RWS HHs 1 0 190.0000
Total: 10 873 1729.3134
To display a chart illustrating the records of Settlement Areas in Lanao del Norte, Region X along with the corresponding number of SPs using the ggplot command in R.
vLDN_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince)  %>%
  group_by(SettlementArea, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vLDN_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 2), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~ SettlementArea, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vRegionX_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Settlement Areas in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Lanao del Norte, Region X table within the database, you can follow the command below:
#Lanao del Norte Settlement Area 1
# Make dataframe
vSettlementArea <- "Lanao del Norte Settlement Area 1"

vLDN_SA1_POTypes_tmp <- vLocations_POTypes %>%
  select(-Municipality, -Barangay) %>%
  drop_na()

vLDN_SA1_POTypes_tmp <- vLDN_SA1_POTypes_tmp %>%
  filter(vLDN_SA1_POTypes_tmp$Region == vRegion, 
         vLDN_SA1_POTypes_tmp$Province == vProvince,
         vLDN_SA1_POTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vLDN_SA1_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Lanao del Norte Settlement Area 1 in Lanao del Norte with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 28 574 645 49 232 0 0 0 0
Farmers Association FA 14 394 154 37 15 0 0 0 0
Irrigators Association IA 3 69 23 17 7 0 0 0 0
Water Users Association WUA 8 294 187 0 0 0 0 0 0
Womens Organization WO 2 0 25 0 0 0 0 0 0
Total: 55 1331 1034 103 254 0 0 0 0
#Lanao del Norte Settlement Area 2
# Make dataframe
vSettlementArea <- "Lanao del Norte Settlement Area 2"

vLDN_SA2_POTypes_tmp <- vLocations_POTypes %>%
  select(-Municipality, -Barangay) %>%
  drop_na()

vLDN_SA2_POTypes_tmp <- vLDN_SA2_POTypes_tmp %>%
  filter(vLDN_SA2_POTypes_tmp$Region == vRegion, 
         vLDN_SA2_POTypes_tmp$Province == vProvince,
         vLDN_SA2_POTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vLDN_SA2_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Lanao del Norte Settlement Area 2 in Lanao del Norte with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 5 47 33 22 8 15 22 5 3
Irrigators Association IA 1 0 0 0 0 0 0 0 0
Total: 6 47 33 22 8 15 22 5 3
#Lanao del Norte Settlement Area 3
# Make dataframe
vSettlementArea <- "Lanao del Norte Settlement Area 3"

vLDN_SA3_POTypes_tmp <- vLocations_POTypes %>%
  select(-Municipality, -Barangay) %>%
  drop_na()

vLDN_SA3_POTypes_tmp <- vLDN_SA3_POTypes_tmp %>%
  filter(vLDN_SA3_POTypes_tmp$Region == vRegion, 
         vLDN_SA3_POTypes_tmp$Province == vProvince,
         vLDN_SA3_POTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vLDN_SA3_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Lanao del Norte Settlement Area 3 in Lanao del Norte with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 3 95 65 31 20 0 0 0 0
Farmers Association FA 2 12 18 0 0 0 0 0 0
Water Users Association WUA 1 62 0 0 0 0 0 0 0
Total: 6 169 83 31 20 0 0 0 0
To display a chart illustrating the records of Settlement Areas in Lanao del Norte, Region X along with the corresponding number of POs using the ggplot command in R.
vSA_LDN_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == "Region X", 
         vLocations_POTypes$Province == "Lanao del Norte")  %>%
  group_by(SettlementArea, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vSA_LDN_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~SettlementArea, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vLocations_POTypes) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Settlement Areas in", vProvince, vRegion, "and PO Types with No. of PO Group"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Davao de Oro, Region XI with SP Types table within the database, you can follow the command below:
vRegion <- "Region XI"
vProvince <- "Davao de Oro"
vSettlementArea <- "Karagan Valley Settlement Area"

vKAR_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Municipality, -Barangay)

vKAR_SA_SPTypes_tmp <- vKAR_SA_SPTypes_tmp %>%
  filter(vKAR_SA_SPTypes_tmp$Region == vRegion, 
         vKAR_SA_SPTypes_tmp$Province == vProvince,
         vKAR_SA_SPTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vKAR_SA_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Karagan Valley Settlement Area in Davao de Oro with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 5 869 840.76
Agro-forestry AGRO Has 2 74 408.90
Crop Intensification CI Has 2 NA 475.00
Farm to Market Road FMR Kms 2 0 16.07
Irrigation IRRIG Has 1 0 106.00
Post Harvest Facilities PHF Units 3 NA 6.00
Rural Water Systems RWS HHs 3 0 629.00
Total: 18 NA 2481.73
To display a chart illustrating the records of Settlement Areas in Davao de Oro, Region XI along with the corresponding number of SPs using the ggplot command in R.
vKAR_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince,
         vLocations_SPTypes$SettlementArea == vSettlementArea)  %>%
  group_by(SettlementArea, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vKAR_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~SettlementArea, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vKAR_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Settlement Areas in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Davao de Oro, Region XI table within the database, you can follow the command below:
#Karagan Valley Settlement Area
# Make dataframe
vKAR_SA_POTypes_tmp <- vLocations_POTypes %>%
  select(-Municipality, -Barangay) %>%
  drop_na()

vKAR_SA_POTypes_tmp <- vKAR_SA_POTypes_tmp %>%
  filter(vKAR_SA_POTypes_tmp$Region == vRegion, 
         vKAR_SA_POTypes_tmp$Province == vProvince,
         vKAR_SA_POTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vKAR_SA_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Karagan Valley Settlement Area in Davao de Oro with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 4 60 54 2 0 61 54 1 0
Farmers Association FA 2 650 324 0 0 650 324 0 0
Irrigators Association IA 2 103 35 0 0 103 35 0 0
Water Users Association WUA 3 515 394 0 0 515 394 0 0
Total: 11 1328 807 2 0 1329 807 1 0
To display a chart illustrating the records of Settlement Areas in Region XI along with the corresponding number of POs using the ggplot command in R.
vSA_KAR_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince,
         vLocations_POTypes$SettlementArea == vSettlementArea)  %>%
  group_by(SettlementArea, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vSA_KAR_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 10, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~SettlementArea, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vSA_KAR_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste(vSettlementArea, vProvince, "and PO Types with No. of PO Group"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Davao del Sur, Region XI with SP Types table within the database, you can follow the command below:
vRegion <- "Region XI"
vProvince <- "Davao del Sur"
vSettlementArea <- "B'laan Settlement Area"

vBLA_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Municipality, -Barangay)

vBLA_SA_SPTypes_tmp <- vBLA_SA_SPTypes_tmp %>%
  filter(vBLA_SA_SPTypes_tmp$Region == vRegion, 
         vBLA_SA_SPTypes_tmp$Province == vProvince,
         vBLA_SA_SPTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vBLA_SA_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
B’laan Settlement Area in Davao del Sur with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 7 1062 1026.29
Bridge BRDG Lms 2 0 55.00
Crop Intensification CI Has 2 NA 474.00
Farm to Market Road FMR Kms 4 0 18.59
Post Harvest Facilities PHF Units 5 NA 6.00
Rural Water Systems RWS HHs 4 0 1257.00
Total: 24 NA 2836.88
To display a chart illustrating the records of Settlement Areas in Davao del Sur, Region XI along with the corresponding number of SPs using the ggplot command in R.
vBLA_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince,
         vLocations_SPTypes$SettlementArea == vSettlementArea)  %>%
  group_by(SettlementArea, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vBLA_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~SettlementArea, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBLA_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Settlement Areas in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Davao del Sur, Region XI table within the database, you can follow the command below:
#B'laan Settlement Area
# Make dataframe
vBLA_SA_POTypes_tmp <- vLocations_POTypes %>%
  select(-Municipality, -Barangay) %>%
  drop_na()

vBLA_SA_POTypes_tmp <- vBLA_SA_POTypes_tmp %>%
  filter(vBLA_SA_POTypes_tmp$Region == vRegion, 
         vBLA_SA_POTypes_tmp$Province == vProvince,
         vBLA_SA_POTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vBLA_SA_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
B’laan Settlement Area in Davao del Sur with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 3 59 103 113 129 0 0 0 0
Farmers Association FA 27 1005 271 507 318 402 148 80 16
Water Users Association WUA 4 24 150 306 132 148 84 218 89
Total: 34 1088 524 926 579 550 232 298 105
To display a chart illustrating the records of Settlement Areas in Region XI along with the corresponding number of POs using the ggplot command in R.
vSA_BLA_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince,
         vLocations_POTypes$SettlementArea == vSettlementArea)  %>%
  group_by(SettlementArea, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vSA_BLA_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 10), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~SettlementArea, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vSA_BLA_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste(vSettlementArea, vProvince, "and PO Types with No. of PO Group"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in North Cotabato, Region XII with SP Types table within the database, you can follow the command below:
vRegion <- "Region XII"
vProvince <- "North Cotabato"
vSettlementArea <- "North Cotabato Settlement Area 1"

vNC_SA1_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Municipality, -Barangay)

vNC_SA1_SPTypes_tmp <- vNC_SA1_SPTypes_tmp %>%
  filter(vNC_SA1_SPTypes_tmp$Region == vRegion, 
         vNC_SA1_SPTypes_tmp$Province == vProvince,
         vNC_SA1_SPTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vNC_SA1_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
North Cotabato Settlement Area 1 in North Cotabato Region XII with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 7 899 870.7972
Agro-forestry AGRO Has 3 60 327.8200
Bridge BRDG Lms 1 0 24.0000
Crop Intensification CI Has 3 NA 1000.0000
Farm to Market Road FMR Kms 4 NA 35.1820
Irrigation IRRIG Has 2 0 284.3300
Post Harvest Facilities PHF Units 5 NA 5.0000
Rural Water Systems RWS HHs 1 0 196.0000
Total: 26 NA 2743.1292
vSettlementArea <- "North Cotabato Settlement Area 2"

vNC_SA2_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Municipality, -Barangay)

vNC_SA2_SPTypes_tmp <- vNC_SA2_SPTypes_tmp %>%
  filter(vNC_SA2_SPTypes_tmp$Region == vRegion, 
         vNC_SA2_SPTypes_tmp$Province == vProvince,
         vNC_SA2_SPTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vNC_SA2_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
North Cotabato Settlement Area 2 in North Cotabato Region XII with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 7 2740 2653.4184
Agro-forestry AGRO Has 5 54 290.0248
Bridge BRDG Lms 1 0 30.0000
Crop Intensification CI Has 2 NA 150.0000
Farm to Market Road FMR Kms 6 0 24.1000
Irrigation IRRIG Has 2 0 166.0000
Post Harvest Facilities PHF Units 4 NA 6.0000
Rural Water Systems RWS HHs 2 0 300.0000
Total: 29 NA 3619.5432
vSettlementArea <- "Sultan Kudarat Settlement Area 1 Phase 2"

vNC_SA3_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Municipality, -Barangay)

vNC_SA3_SPTypes_tmp <- vNC_SA3_SPTypes_tmp %>%
  filter(vNC_SA3_SPTypes_tmp$Region == vRegion, 
         vNC_SA3_SPTypes_tmp$Province == vProvince,
         vNC_SA3_SPTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vNC_SA3_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Sultan Kudarat Settlement Area 1 Phase 2 in North Cotabato Region XII with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 4 1043 1010.348
Agro-forestry AGRO Has 1 89 484.540
Crop Intensification CI Has 1 NA 257.000
Farm to Market Road FMR Kms 3 0 21.040
Post Harvest Facilities PHF Units 5 NA 7.000
Rural Water Systems RWS HHs 3 0 1275.000
Total: 17 NA 3054.928
To display a chart illustrating the records of Settlement Areas in North Cotabato, Region XII along with the corresponding number of SPs using the ggplot command in R.
vNC_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince)  %>%
  group_by(SettlementArea, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vNC_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~SettlementArea, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vNC_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Settlement Areas in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in North Cotabato, Region XII table within the database, you can follow the command below:
#North Cotabato Settlement Area 1
# Make dataframe
vSettlementArea <- "North Cotabato Settlement Area 1"

vNC_SA1_POTypes_tmp <- vLocations_POTypes %>%
  select(-Municipality, -Barangay) %>%
  drop_na()

vNC_SA1_POTypes_tmp <- vNC_SA1_POTypes_tmp %>%
  filter(vNC_SA1_POTypes_tmp$Region == vRegion, 
         vNC_SA1_POTypes_tmp$Province == vProvince,
         vNC_SA1_POTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vNC_SA1_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
North Cotabato Settlement Area 1 in North Cotabato with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 5 130 134 96 258 0 0 226 392
Farmers Association FA 37 994 934 94 68 384 197 677 786
Irrigators Association IA 3 47 9 0 0 0 0 47 9
Water Users Association WUA 1 2 0 93 41 95 41 0 0
Womens Organization WO 6 0 190 0 16 0 0 0 206
Total: 52 1173 1267 283 383 479 238 950 1393
#North Cotabato Settlement Area 2
# Make dataframe
vSettlementArea <- "North Cotabato Settlement Area 2"

vNC_SA2_POTypes_tmp <- vLocations_POTypes %>%
  select(-Municipality, -Barangay) %>%
  drop_na()

vNC_SA2_POTypes_tmp <- vNC_SA2_POTypes_tmp %>%
  filter(vNC_SA2_POTypes_tmp$Region == vRegion, 
         vNC_SA2_POTypes_tmp$Province == vProvince,
         vNC_SA2_POTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vNC_SA2_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
North Cotabato Settlement Area 2 in North Cotabato with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 3 651 973 632 967 0 0 1283 1940
Farmers Association FA 50 569 503 46 724 4 3 565 475
Irrigators Association IA 2 76 42 0 0 0 0 76 42
Water Users Association WUA 2 124 86 0 0 0 0 124 86
Total: 57 1420 1604 678 1691 4 3 2048 2543
#Sultan Kudarat Settlement Area 1 Phase 2
# Make dataframe
vSettlementArea <- "Sultan Kudarat Settlement Area 1 Phase 2"

vNC_SA3_POTypes_tmp <- vLocations_POTypes %>%
  select(-Municipality, -Barangay) %>%
  drop_na()

vNC_SA3_POTypes_tmp <- vNC_SA3_POTypes_tmp %>%
  filter(vNC_SA3_POTypes_tmp$Region == vRegion, 
         vNC_SA3_POTypes_tmp$Province == vProvince,
         vNC_SA3_POTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vNC_SA3_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Sultan Kudarat Settlement Area 1 Phase 2 in North Cotabato with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 3 142 99 12 42 0 0 154 141
Farmers Association FA 31 571 456 32 8 0 0 603 464
Irrigators Association IA 1 21 10 0 0 0 0 21 10
Water Users Association WUA 6 231 117 16 8 0 0 247 125
Womens Organization WO 6 0 192 0 0 0 63 0 255
Total: 47 965 874 60 58 0 63 1025 995
To display a chart illustrating the records of Settlement Areas in North Cotabato, Region XII along with the corresponding number of POs using the ggplot command in R.
vSA_NC_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince)  %>%
  group_by(SettlementArea, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vSA_NC_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 50, by = 10), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~SettlementArea, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vLocations_POTypes) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Settlement Areas in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in South Cotabato, Region XII with SP Types table within the database, you can follow the command below:
# Make dataframe
vRegion <- "Region XII"
vProvince <- "South Cotabato"
vSettlementArea <- "Ned Settlement Area"

vNED_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Municipality, -Barangay)

vNED_SA_SPTypes_tmp <- vNED_SA_SPTypes_tmp %>%
  filter(vNED_SA_SPTypes_tmp$Region == vRegion, 
         vNED_SA_SPTypes_tmp$Province == vProvince,
         vNED_SA_SPTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vNED_SA_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Ned Settlement Area in South Cotabato Region XII with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 4 349 337.8100
Agro-forestry AGRO Has 2 78 425.2482
Bridge BRDG Lms 2 0 27.0000
Crop Intensification CI Has 1 NA 810.0000
Farm to Market Road FMR Kms 4 0 22.2900
Irrigation IRRIG Has 3 0 106.0000
Post Harvest Facilities PHF Units 6 NA 8.0000
Rural Water Systems RWS HHs 2 0 210.0000
Total: 24 NA 1946.3482
To display a chart illustrating the records of Settlement Areas in South Cotabato, Region XII along with the corresponding number of SPs using the ggplot command in R.
vNED_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince)  %>%
  group_by(SettlementArea, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vNED_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~SettlementArea, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vNED_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Settlement Areas in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in South Cotabato, Region XII table within the database, you can follow the command below:
#Ned Settlement Area
vNED_SA_POTypes_tmp <- vLocations_POTypes %>%
  select(-Municipality, -Barangay) %>%
  drop_na()

vNED_SA_POTypes_tmp <- vNED_SA_POTypes_tmp %>%
  filter(vNED_SA_POTypes_tmp$Region == vRegion, 
         vNED_SA_POTypes_tmp$Province == vProvince,
         vNED_SA_POTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vNED_SA_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Ned Settlement Area in South Cotabato with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 6 292 218 109 72 12 0 0 0
Irrigators Association IA 3 0 0 0 0 0 0 0 0
Water Users Association WUA 2 31 25 20 29 3 1 3 1
Total: 11 323 243 129 101 15 1 3 1
To display a chart illustrating the records of Settlement Areas in South Cotabato, Region XII along with the corresponding number of POs using the ggplot command in R.
vSA_NED_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince)  %>%
  group_by(SettlementArea, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vSA_NED_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~SettlementArea, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vLocations_POTypes) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Settlement Areas in", vProvince, vRegion, "and PO Types w/ No. of POs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Sultan Kudarat, Region XII with SP Types table within the database, you can follow the command below:
# Make dataframe
vRegion <- "Region XII"
vProvince <- "Sultan Kudarat"
vSettlementArea <- "Sultan Kudarat Settlement Area 1"

vSK_SA1_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Municipality, -Barangay)

vSK_SA1_SPTypes_tmp <- vSK_SA1_SPTypes_tmp %>%
  filter(vSK_SA1_SPTypes_tmp$Region == vRegion, 
         vSK_SA1_SPTypes_tmp$Province == vProvince,
         vSK_SA1_SPTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vSK_SA1_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Sultan Kudarat Settlement Area 1 in Sultan Kudarat Region XII with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 2 442 428.9653
Agro-forestry AGRO Has 2 74 408.8965
Crop Intensification CI Has 2 150 300.0000
Farm to Market Road FMR Kms 2 0 6.6800
Irrigation IRRIG Has 3 0 657.0000
Post Harvest Facilities PHF Units 1 NA 2.0000
Rural Water Systems RWS HHs 1 0 659.0000
Total: 13 NA 2462.5418
vSettlementArea <- "Sultan Kudarat Settlement Area 2"

vSK_SA2_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Municipality, -Barangay)

vSK_SA2_SPTypes_tmp <- vSK_SA2_SPTypes_tmp %>%
  filter(vSK_SA2_SPTypes_tmp$Region == vRegion, 
         vSK_SA2_SPTypes_tmp$Province == vProvince,
         vSK_SA2_SPTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vSK_SA2_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, vRegion, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Sultan Kudarat Settlement Area 2 in Sultan Kudarat Region XII with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 5 1134 1099.2236
Agro-forestry AGRO Has 4 137 755.6369
Bridge BRDG Lms 1 0 60.0000
Crop Intensification CI Has 7 NA 1460.0000
Farm to Market Road FMR Kms 4 0 30.3300
Irrigation IRRIG Has 1 0 36.0000
Post Harvest Facilities PHF Units 14 NA 17.0000
Rural Water Systems RWS HHs 2 NA 641.0000
Total: 38 NA 4099.1906
To display a chart illustrating the records of Settlement Areas in Sultan Kudarat, Region XII along with the corresponding number of SPs using the ggplot command in R.
vSK_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince)  %>%
  group_by(SettlementArea, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vSK_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~SettlementArea, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vSK_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Settlement Areas in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Sultan Kudarat, Region XII table within the database, you can follow the command below:
#Sultan Kudarat Settlement Area 1
# Make dataframe
vSettlementArea <- "Sultan Kudarat Settlement Area 1"
vSK_SA1_POTypes_tmp <- vLocations_POTypes %>%
  select(-Municipality, -Barangay) %>%
  drop_na()

vSK_SA1_POTypes_tmp <- vSK_SA1_POTypes_tmp %>%
  filter(vSK_SA1_POTypes_tmp$Region == vRegion, 
         vSK_SA1_POTypes_tmp$Province == vProvince,
         vSK_SA1_POTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vSK_SA1_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Sultan Kudarat Settlement Area 1 in Sultan Kudarat with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 1 275 331 0 0 0 0 0 0
Farmers Association FA 13 98 37 43 0 9 0 0 0
Irrigators Association IA 4 187 36 0 0 0 0 0 0
Water Users Association WUA 1 72 57 0 0 0 0 0 0
Total: 19 632 461 43 0 9 0 0 0
#Sultan Kudarat Settlement Area 2
# Make dataframe
vSettlementArea <- "Sultan Kudarat Settlement Area 2"
vSK_SA2_POTypes_tmp <- vLocations_POTypes %>%
  select(-Municipality, -Barangay) %>%
  drop_na()

vSK_SA2_POTypes_tmp <- vSK_SA2_POTypes_tmp %>%
  filter(vSK_SA2_POTypes_tmp$Region == vRegion, 
         vSK_SA2_POTypes_tmp$Province == vProvince,
         vSK_SA2_POTypes_tmp$SettlementArea == vSettlementArea)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vSK_SA2_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vSettlementArea, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Sultan Kudarat Settlement Area 2 in Sultan Kudarat with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 5 308 197 11 10 0 0 0 0
Farmers Association FA 27 990 371 174 78 2 1 299 14
Irrigators Association IA 1 22 6 0 0 0 0 0 0
Water Users Association WUA 2 0 0 0 0 0 0 0 0
Womens Organization WO 8 0 448 0 116 0 0 0 0
Total: 43 1320 1022 185 204 2 1 299 14
To display a chart illustrating the records of Settlement Areas in South Cotabato, Region XII along with the corresponding number of POs using the ggplot command in R.
vSA_SK_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == "Region XII", 
         vLocations_POTypes$Province == "Sultan Kudarat")  %>%
  group_by(SettlementArea, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vSA_SK_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~SettlementArea, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vLocations_POTypes) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Settlement Areas in", vProvince, vRegion, "and PO Types w/ No. of POs"),  
       caption="Data Collected by: Junald A. Lagod")

To retrieve a list of covered Settlement Areas records along with the corresponding number of Municipalities.
To view the Settlements table within the database, you can follow the command below:
vLocSETTLEMENTS_tmp <- vLocations_BRGYS_tmp %>%
  group_by(Region, Province, Settlement, SACode)  %>%
  count(Municipality) %>%
  summarise(Municipalities = n(), .groups = 'drop')

# Make dataframe
results_df <- data.frame(vLocSETTLEMENTS_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("Region", "Province", "Settlement", "Code", "No. of Municipalities", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Covered Settlement Areas table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Covered Settlement Areas table
Region Province Settlement Code No. of Municipalities
Region X Bukidnon Kadingilan Settlement Area KAD-SA 1
Region X Lanao del Norte Lanao del Norte Settlement Area 1 LDN1-SA 7
Region X Lanao del Norte Lanao del Norte Settlement Area 2 LDN2-SA 1
Region X Lanao del Norte Lanao del Norte Settlement Area 3 LDN3-SA 2
Region XI Davao de Oro Karagan Valley Settlement Area KAR-SA 2
Region XI Davao del Sur B’laan Settlement Area BLA-SA 2
Region XII North Cotabato North Cotabato Settlement Area 1 NC1-SA 2
Region XII North Cotabato North Cotabato Settlement Area 2 NC2-SA 3
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 SK1-P2-SA 2
Region XII South Cotabato Ned Settlement Area NED-SA 1
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 SK1-SA 1
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 SK2-SA 3
Total: 27
To display a chart illustrating the records of Settlements along with the corresponding number of Municipalities using the ggplot command in R.
ggplot(vLocSETTLEMENTS_tmp) +
  geom_col(aes(as.integer(Municipalities), Settlement), fill = "#ABC123", width = 0.6)  + 
  geom_text(data = subset(vLocSETTLEMENTS_tmp, Municipalities >= 1),
    aes(0, y = Settlement, label = Settlement), hjust = 0, size = 3) +
    scale_x_continuous(
      breaks = seq(0, 10, by = 1), 
      expand = c(0, 0), # The horizontal axis does not extend to either side
      position = "top"  # Labels are located on the top
    )  +
    theme(axis.text.y = element_blank()) +
    xlab("Number of Municipalities") + ylab("Settlement Areas") + 
    labs(title= "Covered Settlements with Number of Municipalities", 
         caption="Data Collected by: Junald A. Lagod")  

To view the Settlement Areas in Bukidnon, Region X with SP Types table within the database, you can follow the command below:
vRegion <- "Region X"
vProvince <- "Bukidnon"
vSettlementArea <- "Kadingilan Settlement Area"
vMunicipality <- "Kadingilan"

vKAD_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vKAD_MUN_SPTypes_tmp <- vKAD_MUN_SPTypes_tmp %>%
  filter(vKAD_MUN_SPTypes_tmp$Region == vRegion, 
         vKAD_MUN_SPTypes_tmp$Province == vProvince,
         vKAD_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vKAD_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vKAD_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Kadingilan Bukidnon with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 6 501 485.2685
Bridge BRDG Lms 1 0 18.0000
Crop Intensification CI Has 2 NA 300.0000
Farm to Market Road FMR Kms 3 0 12.6300
Irrigation IRRIG Has 3 0 265.0000
Post Harvest Facilities PHF Units 9 NA 11.0000
Rural Water Systems RWS HHs 1 0 212.0000
Total: 25 NA 1303.8985
To display a chart illustrating the records of Municipalities in Bukidnon, Region X along with the corresponding number of SPs using the ggplot command in R.
vKAD_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince,
         vLocations_SPTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vKAD_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vKAD_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Municipalities in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Kadingilan, Bukidnon, Region X table within the database, you can follow the command below:
#Kadingilan
# Make dataframe
vKAD_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vKAD_POTypes_tmp <- vKAD_POTypes_tmp %>%
  filter(vKAD_POTypes_tmp$Region == vRegion, 
         vKAD_POTypes_tmp$Province == vProvince,
         vKAD_POTypes_tmp$SettlementArea == vSettlementArea,
         vKAD_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vKAD_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Kadingilan in Bukidnon with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 2 123 30 4 104 0 0 0 0
Farmers Association FA 3 32 9 50 31 0 0 0 0
Irrigators Association IA 1 19 7 55 13 0 0 0 0
Water Users Association WUA 1 149 56 5 0 0 0 0 0
Womens Organization WO 1 0 16 0 30 0 0 0 0
Total: 8 323 118 114 178 0 0 0 0
To display a chart illustrating the records of Kadingilan Settlement Area in Bukidnon, Region X along with the corresponding number of POs using the ggplot command in R.
vKAD_SA_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince,
         vLocations_POTypes$SettlementArea == vSettlementArea,
         vLocations_POTypes$Municipality == vMunicipality)  %>%
  group_by(SettlementArea, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vKAD_SA_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~SettlementArea, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vKAD_SA_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste(vMunicipality, "in", vProvince, "with PO Types table"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Lanao del Norte, Region X with SP Types table within the database, you can follow the command below:
vRegion <- "Region X"
vProvince <- "Lanao del Norte"
vSettlementArea <- "Lanao del Norte Settlement Area 1"
vMunicipality <- "Kolambugan"

vKOL_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vKOL_MUN_SPTypes_tmp <- vKOL_MUN_SPTypes_tmp %>%
  filter(vKOL_MUN_SPTypes_tmp$Region == vRegion, 
         vKOL_MUN_SPTypes_tmp$Province == vProvince,
         vKOL_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vKOL_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vKOL_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Kolambugan Lanao del Norte with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 2 17 16.08620
Agro-forestry AGRO Has 1 4 20.44482
Farm to Market Road FMR Kms 1 0 6.02000
Post Harvest Facilities PHF Units 1 0 1.00000
Rural Water Systems RWS HHs 1 0 473.00000
Total: 6 21 516.55102
vMunicipality <- "Magsaysay"

vMAG1_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vMAG1_MUN_SPTypes_tmp <- vMAG1_MUN_SPTypes_tmp %>%
  filter(vMAG1_MUN_SPTypes_tmp$Region == vRegion, 
         vMAG1_MUN_SPTypes_tmp$Province == vProvince,
         vMAG1_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vMAG1_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vMAG1_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Magsaysay Lanao del Norte with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 2 61 58.98207
Agro-forestry AGRO Has 3 280 1531.31948
Farm to Market Road FMR Kms 1 0 7.46000
Irrigation IRRIG Has 1 0 20.00000
Post Harvest Facilities PHF Units 1 NA 2.00000
Rural Water Systems RWS HHs 1 0 220.00000
Total: 9 NA 1839.76154
vMunicipality <- "Maigo"

vMAI_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vMAI_MUN_SPTypes_tmp <- vMAI_MUN_SPTypes_tmp %>%
  filter(vMAI_MUN_SPTypes_tmp$Region == vRegion, 
         vMAI_MUN_SPTypes_tmp$Province == vProvince,
         vMAI_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vMAI_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vMAI_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Maigo Lanao del Norte with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 3 1056 1022.546
Bridge BRDG Lms 1 0 30.000
Farm to Market Road FMR Kms 1 0 11.150
Post Harvest Facilities PHF Units 1 0 2.000
Total: 6 1056 1065.696
vMunicipality <- "Munai"

vMUN_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vMUN_MUN_SPTypes_tmp <- vMUN_MUN_SPTypes_tmp %>%
  filter(vMUN_MUN_SPTypes_tmp$Region == vRegion, 
         vMUN_MUN_SPTypes_tmp$Province == vProvince,
         vMUN_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vMUN_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vMUN_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Munai Lanao del Norte with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 1 55 53.62066
Agro-forestry AGRO Has 3 106 582.67750
Bridge BRDG Lms 1 0 80.00000
Farm to Market Road FMR Kms 1 0 7.93000
Post Harvest Facilities PHF Units 2 NA 3.00000
Rural Water Systems RWS HHs 1 0 176.00000
Total: 9 NA 903.22817
vMunicipality <- "Pantao Ragat"

vPAN_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vPAN_MUN_SPTypes_tmp <- vPAN_MUN_SPTypes_tmp %>%
  filter(vPAN_MUN_SPTypes_tmp$Region == vRegion, 
         vPAN_MUN_SPTypes_tmp$Province == vProvince,
         vPAN_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vPAN_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vPAN_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Pantao Ragat Lanao del Norte with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 2 304 294.9127
Bridge BRDG Lms 1 0 50.0000
Farm to Market Road FMR Kms 1 0 3.9500
Post Harvest Facilities PHF Units 2 NA 3.0000
Rural Water Systems RWS HHs 2 0 389.0000
Total: 8 NA 740.8627
vMunicipality <- "Tangcal"

vTAN_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vTAN_MUN_SPTypes_tmp <- vTAN_MUN_SPTypes_tmp %>%
  filter(vTAN_MUN_SPTypes_tmp$Region == vRegion, 
         vTAN_MUN_SPTypes_tmp$Province == vProvince,
         vTAN_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vTAN_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vTAN_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Tangcal Lanao del Norte with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 1 111 107.2413
Agro-forestry AGRO Has 2 49 265.7800
Bridge BRDG Lms 1 0 18.0000
Farm to Market Road FMR Kms 1 0 5.9700
Irrigation IRRIG Has 1 0 40.0000
Post Harvest Facilities PHF Units 1 NA 2.0000
Rural Water Systems RWS HHs 1 0 250.0000
Total: 8 NA 688.9913
vMunicipality <- "Tubod"

vTUB_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vTUB_MUN_SPTypes_tmp <- vTUB_MUN_SPTypes_tmp %>%
  filter(vTUB_MUN_SPTypes_tmp$Region == vRegion, 
         vTUB_MUN_SPTypes_tmp$Province == vProvince,
         vTUB_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vTUB_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vTUB_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Tubod Lanao del Norte with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 1 166 160.8620
Agro-forestry AGRO Has 2 41 224.8948
Farm to Market Road FMR Kms 1 0 8.8400
Irrigation IRRIG Has 1 0 130.0000
Post Harvest Facilities PHF Units 1 NA 1.0000
Total: 6 NA 525.5968
To display a chart illustrating the records of Municipalities in Lanao del Norte, Region X along with the corresponding number of SPs using the ggplot command in R.
vLDN_SA1_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince,
         vLocations_SPTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vLDN_SA1_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vLDN_SA1_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Municipalities in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Area 1 in Lanao del Norte, Region X table within the database, you can follow the command below:
#Kolambugan
# Make dataframe
vMunicipality <- "Kolambugan"

vKOL_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vKOL_POTypes_tmp <- vKOL_POTypes_tmp %>%
  filter(vKOL_POTypes_tmp$Region == vRegion, 
         vKOL_POTypes_tmp$Province == vProvince,
         vKOL_POTypes_tmp$SettlementArea == vSettlementArea,
         vKOL_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vKOL_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Kolambugan in Lanao del Norte with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 6 90 213 6 17 0 0 0 0
Farmers Association FA 3 0 0 0 0 0 0 0 0
Water Users Association WUA 2 27 37 0 0 0 0 0 0
Total: 11 117 250 6 17 0 0 0 0
#Magsaysay
# Make dataframe
vMunicipality <- "Magsaysay"
vMAG1_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vMAG1_POTypes_tmp <- vMAG1_POTypes_tmp %>%
  filter(vMAG1_POTypes_tmp$Region == vRegion, 
         vMAG1_POTypes_tmp$Province == vProvince,
         vMAG1_POTypes_tmp$SettlementArea == vSettlementArea,
         vMAG1_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')


results_df <- data.frame(vMAG1_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Magsaysay in Lanao del Norte with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 9 114 148 0 6 0 0 0 0
Irrigators Association IA 1 0 0 0 0 0 0 0 0
Water Users Association WUA 1 82 83 0 0 0 0 0 0
Total: 11 196 231 0 6 0 0 0 0
#Maigo
# Make dataframe
vMunicipality <- "Maigo"
vMAI_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vMAI_POTypes_tmp <- vMAI_POTypes_tmp %>%
  filter(vMAI_POTypes_tmp$Region == vRegion, 
         vMAI_POTypes_tmp$Province == vProvince,
         vMAI_POTypes_tmp$SettlementArea == vSettlementArea,
         vMAI_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')


results_df <- data.frame(vMAI_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Maigo in Lanao del Norte with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 1 23 12 14 6 0 0 0 0
Farmers Association FA 2 331 120 0 0 0 0 0 0
Total: 3 354 132 14 6 0 0 0 0
#Munai
# Make dataframe
vMunicipality <- "Munai"
vMUN_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vMUN_POTypes_tmp <- vMUN_POTypes_tmp %>%
  filter(vMUN_POTypes_tmp$Region == vRegion, 
         vMUN_POTypes_tmp$Province == vProvince,
         vMUN_POTypes_tmp$SettlementArea == vSettlementArea,
         vMUN_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vMUN_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Munai in Lanao del Norte with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 2 23 33 23 61 0 0 0 0
Farmers Association FA 5 49 23 37 15 0 0 0 0
Water Users Association WUA 1 40 9 0 0 0 0 0 0
Total: 8 112 65 60 76 0 0 0 0
#Pantao Ragat
# Make dataframe
vMunicipality <- "Pantao Ragat"
vPAN_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vPAN_POTypes_tmp <- vPAN_POTypes_tmp %>%
  filter(vPAN_POTypes_tmp$Region == vRegion, 
         vPAN_POTypes_tmp$Province == vProvince,
         vPAN_POTypes_tmp$SettlementArea == vSettlementArea,
         vPAN_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vPAN_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Pantao Ragat in Lanao del Norte with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 4 93 44 0 67 0 0 0 0
Farmers Association FA 1 0 0 0 0 0 0 0 0
Water Users Association WUA 2 95 48 0 0 0 0 0 0
Total: 7 188 92 0 67 0 0 0 0
#Tangcal
# Make dataframe
vMunicipality <- "Tangcal"
vTAN_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vTAN_POTypes_tmp <- vTAN_POTypes_tmp %>%
  filter(vTAN_POTypes_tmp$Region == vRegion, 
         vTAN_POTypes_tmp$Province == vProvince,
         vTAN_POTypes_tmp$SettlementArea == vSettlementArea,
         vTAN_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vTAN_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Tangcal in Lanao del Norte with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 3 40 57 0 0 0 0 0 0
Farmers Association FA 3 14 11 0 0 0 0 0 0
Irrigators Association IA 1 27 9 17 7 0 0 0 0
Water Users Association WUA 2 50 10 0 0 0 0 0 0
Womens Organization WO 2 0 25 0 0 0 0 0 0
Total: 11 131 112 17 7 0 0 0 0
#Tubod
# Make dataframe
vMunicipality <- "Tubod"
vTUB_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vTUB_POTypes_tmp <- vTUB_POTypes_tmp %>%
  filter(vTUB_POTypes_tmp$Region == vRegion, 
         vTUB_POTypes_tmp$Province == vProvince,
         vTUB_POTypes_tmp$SettlementArea == vSettlementArea,
         vTUB_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vTUB_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Tubod in Lanao del Norte with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 3 191 138 6 75 0 0 0 0
Irrigators Association IA 1 42 14 0 0 0 0 0 0
Total: 4 233 152 6 75 0 0 0 0
To display a chart illustrating the records of Lanao del Norte Settlement Area 1 in Lanao del Norte, Region X along with the corresponding number of POs using the ggplot command in R.
vSettlementArea <- "Lanao del Norte Settlement Area 1"
vLDNSA1_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince,
         vLocations_POTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vLDNSA1_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 2), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vLDNSA1_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste(vSettlementArea, "in", vProvince, "with PO Types table"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Lanao del Norte, Region X with SP Types table within the database, you can follow the command below:
vRegion <- "Region X"
vProvince <- "Lanao del Norte"
vSettlementArea <- "Lanao del Norte Settlement Area 2"
vMunicipality <- "Sapad"

vSAP_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vSAP_MUN_SPTypes_tmp <- vSAP_MUN_SPTypes_tmp %>%
  filter(vSAP_MUN_SPTypes_tmp$Region == vRegion, 
         vSAP_MUN_SPTypes_tmp$Province == vProvince,
         vSAP_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vSAP_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vSAP_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Sapad Lanao del Norte with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 3 471 455.77
Agro-forestry AGRO Has 2 112 613.35
Bridge BRDG Lms 3 0 385.00
Farm to Market Road FMR Kms 1 0 1.98
Irrigation IRRIG Has 1 0 120.00
Post Harvest Facilities PHF Units 1 NA 2.00
Total: 11 NA 1578.10
To display a chart illustrating the records of Municipalities in Lanao del Norte, Region X along with the corresponding number of SPs using the ggplot command in R.
vLDN2_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince,
         vLocations_SPTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vLDN2_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vLDN2_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Municipalities in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Area 2 in Lanao del Norte, Region X table within the database, you can follow the command below:
#Sapad
# Make dataframe
vSAP_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vSAP_POTypes_tmp <- vSAP_POTypes_tmp %>%
  filter(vSAP_POTypes_tmp$Region == vRegion, 
         vSAP_POTypes_tmp$Province == vProvince,
         vSAP_POTypes_tmp$SettlementArea == vSettlementArea,
         vSAP_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vSAP_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Sapad in Lanao del Norte with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 5 47 33 22 8 15 22 5 3
Irrigators Association IA 1 0 0 0 0 0 0 0 0
Total: 6 47 33 22 8 15 22 5 3
To display a chart illustrating the records of Lanao del Norte Settlement Area 2 in Lanao del Norte, Region X along with the corresponding number of POs using the ggplot command in R.
vLDNSA2_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince,
         vLocations_POTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vLDNSA2_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vLDNSA2_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste(vSettlementArea, "in", vProvince, "with PO Types table"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Lanao del Norte, Region X with SP Types table within the database, you can follow the command below:
vRegion <- "Region X"
vProvince <- "Lanao del Norte"
vSettlementArea <- "Lanao del Norte Settlement Area 3"
vMunicipality <- "Nunungan"

vNUN_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vNUN_MUN_SPTypes_tmp <- vNUN_MUN_SPTypes_tmp %>%
  filter(vNUN_MUN_SPTypes_tmp$Region == vRegion, 
         vNUN_MUN_SPTypes_tmp$Province == vProvince,
         vNUN_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vNUN_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vNUN_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Nunungan Lanao del Norte with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 1 138 134.0500
Agro-forestry AGRO Has 2 78 429.3431
Post Harvest Facilities PHF Units 2 0 3.0000
Rural Water Systems RWS HHs 1 0 190.0000
Total: 6 216 756.3931
vMunicipality <- "Sultan Naga Dimaporo"

vSND_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vSND_MUN_SPTypes_tmp <- vSND_MUN_SPTypes_tmp %>%
  filter(vSND_MUN_SPTypes_tmp$Region == vRegion, 
         vSND_MUN_SPTypes_tmp$Province == vProvince,
         vSND_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vSND_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vSND_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Sultan Naga Dimaporo Lanao del Norte with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 2 582 563.0203
Agro-forestry AGRO Has 1 75 408.9000
Post Harvest Facilities PHF Units 1 0 1.0000
Total: 4 657 972.9203
To display a chart illustrating the records of Municipalities in Lanao del Norte, Region X along with the corresponding number of SPs using the ggplot command in R.
vLDN3_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince,
         vLocations_SPTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vLDN3_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vLDN3_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Municipalities in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Area 2 in Lanao del Norte, Region X table within the database, you can follow the command below:
#Nunungan
# Make dataframe
vMunicipality <- "Nunungan"

vNUN_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vNUN_POTypes_tmp <- vNUN_POTypes_tmp %>%
  filter(vNUN_POTypes_tmp$Region == vRegion, 
         vNUN_POTypes_tmp$Province == vProvince,
         vNUN_POTypes_tmp$SettlementArea == vSettlementArea,
         vNUN_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vNUN_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Nunungan in Lanao del Norte with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 2 52 28 31 20 0 0 0 0
Farmers Association FA 1 0 0 0 0 0 0 0 0
Water Users Association WUA 1 62 0 0 0 0 0 0 0
Total: 4 114 28 31 20 0 0 0 0
#Sultan Naga Dimaporo
# Make dataframe
vMunicipality <- "Sultan Naga Dimaporo"
vSND_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vSND_POTypes_tmp <- vSND_POTypes_tmp %>%
  filter(vSND_POTypes_tmp$Region == vRegion, 
         vSND_POTypes_tmp$Province == vProvince,
         vSND_POTypes_tmp$SettlementArea == vSettlementArea,
         vSND_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vSND_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Sultan Naga Dimaporo in Lanao del Norte with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 1 43 37 0 0 0 0 0 0
Farmers Association FA 1 12 18 0 0 0 0 0 0
Total: 2 55 55 0 0 0 0 0 0
To display a chart illustrating the records of Lanao del Norte Settlement Area 3 in Lanao del Norte, Region X along with the corresponding number of POs using the ggplot command in R.
vLDNSA3_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince,
         vLocations_POTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vLDNSA3_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vLDNSA3_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste(vSettlementArea, "in", vProvince, "with PO Types table"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Davao de Oro, Region XI with SP Types table within the database, you can follow the command below:
vRegion <- "Region XI"
vProvince <- "Davao de Oro"
vSettlementArea <- "Karagan Valley Settlement Area"
vMunicipality <- "Maragusan"

vMAR_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vMAR_MUN_SPTypes_tmp <- vMAR_MUN_SPTypes_tmp %>%
  filter(vMAR_MUN_SPTypes_tmp$Region == vRegion, 
         vMAR_MUN_SPTypes_tmp$Province == vProvince,
         vMAR_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vMAR_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vMAR_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Maragusan Davao de Oro with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 1 28 26.81
Crop Intensification CI Has 2 NA 475.00
Farm to Market Road FMR Kms 1 0 10.32
Irrigation IRRIG Has 1 0 106.00
Post Harvest Facilities PHF Units 2 NA 4.00
Rural Water Systems RWS HHs 2 0 339.00
Total: 9 NA 961.13
vMunicipality <- "New Bataan"

vNEW_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vNEW_MUN_SPTypes_tmp <- vNEW_MUN_SPTypes_tmp %>%
  filter(vNEW_MUN_SPTypes_tmp$Region == vRegion, 
         vNEW_MUN_SPTypes_tmp$Province == vProvince,
         vNEW_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vNEW_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vNEW_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
New Bataan Davao de Oro with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 4 841 813.95
Agro-forestry AGRO Has 2 74 408.90
Farm to Market Road FMR Kms 1 0 5.75
Post Harvest Facilities PHF Units 1 NA 2.00
Rural Water Systems RWS HHs 1 0 290.00
Total: 9 NA 1520.60
To display a chart illustrating the records of Municipalities in Davao de Oro, Region XI along with the corresponding number of SPs using the ggplot command in R.
vKAR_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince,
         vLocations_SPTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vKAR_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vKAR_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Municipalities in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Davao de Oro, Region XI table within the database, you can follow the command below:
#Maragusan
# Make dataframe
vMunicipality <- "Maragusan"

vMAR_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vMAR_POTypes_tmp <- vLocations_POTypes %>%
  filter(vMAR_POTypes_tmp$Region == vRegion, 
         vMAR_POTypes_tmp$Province == vProvince,
         vMAR_POTypes_tmp$SettlementArea == vSettlementArea,
         vMAR_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vMAR_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Maragusan in Davao de Oro with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 2 60 54 2 0 61 54 1 0
Farmers Association FA 2 650 324 0 0 650 324 0 0
Irrigators Association IA 1 40 9 0 0 40 9 0 0
Water Users Association WUA 2 240 254 0 0 240 254 0 0
Total: 7 990 641 2 0 991 641 1 0
#New Bataan
# Make dataframe
vMunicipality <- "New Bataan"

vNEW_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vNEW_POTypes_tmp <- vLocations_POTypes %>%
  filter(vNEW_POTypes_tmp$Region == vRegion, 
         vNEW_POTypes_tmp$Province == vProvince,
         vNEW_POTypes_tmp$SettlementArea == vSettlementArea,
         vNEW_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vNEW_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
New Bataan in Davao de Oro with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 2 0 0 0 0 0 0 0 0
Irrigators Association IA 1 63 26 0 0 63 26 0 0
Water Users Association WUA 1 275 140 0 0 275 140 0 0
Total: 4 338 166 0 0 338 166 0 0
To display a chart illustrating the records of Karagan Valley Settlement Area in Davao de Oro, Region XI along with the corresponding number of POs using the ggplot command in R.
vKARSA_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince,
         vLocations_POTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vKARSA_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vKARSA_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste(vSettlementArea, "in", vProvince, "with PO Types table"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Davao del Sur, Region XI with SP Types table within the database, you can follow the command below:
vRegion <- "Region XI"
vProvince <- "Davao del Sur"
vSettlementArea <- "B'laan Settlement Area"
vMunicipality <- "Magsaysay"

vMAG2_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vMAG2_MUN_SPTypes_tmp <- vMAG2_MUN_SPTypes_tmp %>%
  filter(vMAG2_MUN_SPTypes_tmp$Region == vRegion, 
         vMAG2_MUN_SPTypes_tmp$Province == vProvince,
         vMAG2_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vMAG2_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vMAG2_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Magsaysay Davao del Sur with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 3 335 323.33
Bridge BRDG Lms 1 0 25.00
Crop Intensification CI Has 2 NA 474.00
Farm to Market Road FMR Kms 2 0 11.46
Post Harvest Facilities PHF Units 2 NA 2.00
Rural Water Systems RWS HHs 2 0 600.00
Total: 12 NA 1435.79
vMunicipality <- "Matanao"

vMAT_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vMAT_MUN_SPTypes_tmp <- vMAT_MUN_SPTypes_tmp %>%
  filter(vMAT_MUN_SPTypes_tmp$Region == vRegion, 
         vMAT_MUN_SPTypes_tmp$Province == vProvince,
         vMAT_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vMAT_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vMAT_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Matanao Davao del Sur with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 4 727 702.9603
Bridge BRDG Lms 1 0 30.0000
Farm to Market Road FMR Kms 2 0 7.1300
Post Harvest Facilities PHF Units 3 NA 4.0000
Rural Water Systems RWS HHs 2 0 657.0000
Total: 12 NA 1401.0903
To display a chart illustrating the records of Municipalities in Davao del Sur, Region XI along with the corresponding number of SPs using the ggplot command in R.
vBLA_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince,
         vLocations_SPTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vBLA_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBLA_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Municipalities in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Davao del Sur, Region XI table within the database, you can follow the command below:
#Magsaysay
# Make dataframe
vMunicipality <- "Magsaysay"

vMAG2_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vMAG2_POTypes_tmp <- vMAG2_POTypes_tmp %>%
  filter(vMAG2_POTypes_tmp$Region == vRegion, 
         vMAG2_POTypes_tmp$Province == vProvince,
         vMAG2_POTypes_tmp$SettlementArea == vSettlementArea,
         vMAG2_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vMAG2_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Magsaysay in Davao del Sur with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 2 19 21 65 93 0 0 0 0
Farmers Association FA 5 241 61 195 193 0 0 0 0
Water Users Association WUA 2 12 26 286 108 134 52 218 89
Total: 9 272 108 546 394 134 52 218 89
#Matanao
# Make dataframe
vMunicipality <-  "Matanao"

vMAT_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vMAT_POTypes_tmp <- vMAT_POTypes_tmp %>%
  filter(vMAT_POTypes_tmp$Region == vRegion, 
         vMAT_POTypes_tmp$Province == vProvince,
         vMAT_POTypes_tmp$SettlementArea == vSettlementArea,
         vMAT_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vMAT_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Matanao in Davao del Sur with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 1 40 82 48 36 0 0 0 0
Farmers Association FA 22 764 210 312 125 402 148 80 16
Water Users Association WUA 2 12 124 20 24 14 32 0 0
Total: 25 816 416 380 185 416 180 80 16
To display a chart illustrating the records of B’laan Valley Settlement Area in Davao del Sur, Region XI along with the corresponding number of POs using the ggplot command in R.
vBLASA_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince,
         vLocations_POTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBLASA_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBLASA_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste(vSettlementArea, "in", vProvince, "with PO Types table"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in North Cotabato, Region XII with SP Types table within the database, you can follow the command below:
vRegion <- "Region XII"
vProvince <- "North Cotabato"
vSettlementArea <- "North Cotabato Settlement Area 1"
vMunicipality <-  "Banisilan"

vBAN_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vBAN_MUN_SPTypes_tmp <- vBAN_MUN_SPTypes_tmp %>%
  filter(vBAN_MUN_SPTypes_tmp$Region == vRegion, 
         vBAN_MUN_SPTypes_tmp$Province == vProvince,
         vBAN_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vBAN_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vBAN_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Banisilan North Cotabato with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 5 595 576.4172
Agro-forestry AGRO Has 1 10 57.2500
Bridge BRDG Lms 1 0 24.0000
Crop Intensification CI Has 3 NA 1000.0000
Farm to Market Road FMR Kms 2 0 7.4900
Irrigation IRRIG Has 2 0 284.3300
Post Harvest Facilities PHF Units 4 NA 4.0000
Total: 18 NA 1953.4872
vMunicipality <- "Carmen"

vCAR_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vCAR_MUN_SPTypes_tmp <- vCAR_MUN_SPTypes_tmp %>%
  filter(vCAR_MUN_SPTypes_tmp$Region == vRegion, 
         vCAR_MUN_SPTypes_tmp$Province == vProvince,
         vCAR_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vCAR_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vCAR_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Carmen North Cotabato with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 2 304 294.380
Agro-forestry AGRO Has 2 50 270.570
Farm to Market Road FMR Kms 2 NA 27.692
Post Harvest Facilities PHF Units 1 NA 1.000
Rural Water Systems RWS HHs 1 0 196.000
Total: 8 NA 789.642
To display a chart illustrating the records of Municipalities in Davao del Sur, Region XI along with the corresponding number of SPs using the ggplot command in R.
vNC1_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince,
         vLocations_SPTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vNC1_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vNC1_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Municipalities in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the North Cotabato Settlement Area 1 in North Cotabato, Region XII table within the database, you can follow the command below:
#Banisilan
# Make dataframe
vMunicipality <-  "Banisilan"

vBAN_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vBAN_POTypes_tmp <- vBAN_POTypes_tmp %>%
  filter(vBAN_POTypes_tmp$Region == vRegion, 
         vBAN_POTypes_tmp$Province == vProvince,
         vBAN_POTypes_tmp$SettlementArea == vSettlementArea,
         vBAN_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vBAN_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Banisilan in North Cotabato with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 5 130 134 96 258 0 0 226 392
Farmers Association FA 29 684 785 22 20 2 0 677 786
Irrigators Association IA 3 47 9 0 0 0 0 47 9
Womens Organization WO 6 0 190 0 16 0 0 0 206
Total: 43 861 1118 118 294 2 0 950 1393
#Carmen
# Make dataframe
vMunicipality <-  "Carmen"

vCAR_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vCAR_POTypes_tmp <- vCAR_POTypes_tmp %>%
  filter(vCAR_POTypes_tmp$Region == vRegion, 
         vCAR_POTypes_tmp$Province == vProvince,
         vCAR_POTypes_tmp$SettlementArea == vSettlementArea,
         vCAR_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vCAR_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Carmen in North Cotabato with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Farmers Association FA 8 310 149 72 48 382 197 0 0
Water Users Association WUA 1 2 0 93 41 95 41 0 0
Total: 9 312 149 165 89 477 238 0 0
To display a chart illustrating the records of North Cotabato Settlement Area 1 in North Cotabato, Region XII along with the corresponding number of POs using the ggplot command in R.
vNCSA1_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince,
         vLocations_POTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vNCSA1_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 10), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vNCSA1_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste(vSettlementArea, "in", vProvince, "with PO Types table"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in North Cotabato, Region XII with SP Types table within the database, you can follow the command below:
vRegion <- "Region XII"
vProvince <- "North Cotabato"
vSettlementArea <- "North Cotabato Settlement Area 2"
vMunicipality <-  "Alamada"

vALA_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vALA_MUN_SPTypes_tmp <- vALA_MUN_SPTypes_tmp %>%
  filter(vALA_MUN_SPTypes_tmp$Region == vRegion, 
         vALA_MUN_SPTypes_tmp$Province == vProvince,
         vALA_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vALA_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vALA_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Alamada North Cotabato with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 5 2654 2570.038
Agro-forestry AGRO Has 1 4 20.440
Bridge BRDG Lms 1 0 30.000
Crop Intensification CI Has 1 50 50.000
Farm to Market Road FMR Kms 4 0 17.890
Irrigation IRRIG Has 2 0 166.000
Post Harvest Facilities PHF Units 2 NA 3.000
Rural Water Systems RWS HHs 1 0 150.000
Total: 17 NA 3007.368
vMunicipality <- "Libungan"

vLIB_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vLIB_MUN_SPTypes_tmp <- vLIB_MUN_SPTypes_tmp %>%
  filter(vLIB_MUN_SPTypes_tmp$Region == vRegion, 
         vLIB_MUN_SPTypes_tmp$Province == vProvince,
         vLIB_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vLIB_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vLIB_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Libungan North Cotabato with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 2 86 83.38
Agro-forestry AGRO Has 2 21 110.12
Farm to Market Road FMR Kms 1 0 2.43
Post Harvest Facilities PHF Units 1 NA 2.00
Total: 6 NA 197.93
vMunicipality <- "Pigcawayan"

vPIG_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vPIG_MUN_SPTypes_tmp <- vPIG_MUN_SPTypes_tmp %>%
  filter(vPIG_MUN_SPTypes_tmp$Region == vRegion, 
         vPIG_MUN_SPTypes_tmp$Province == vProvince,
         vPIG_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vPIG_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vPIG_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Pigcawayan North Cotabato with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agro-forestry AGRO Has 2 29 159.4648
Crop Intensification CI Has 1 NA 100.0000
Farm to Market Road FMR Kms 1 0 3.7800
Post Harvest Facilities PHF Units 1 NA 1.0000
Rural Water Systems RWS HHs 1 0 150.0000
Total: 6 NA 414.2448
To display a chart illustrating the records of Municipalities in Davao del Sur, Region XI along with the corresponding number of SPs using the ggplot command in R.
vNC2_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince,
         vLocations_SPTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vNC2_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vNC2_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Municipalities in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the North Cotabato Settlement Area 2 in North Cotabato, Region XII table within the database, you can follow the command below:
#Alamada
# Make dataframe
vMunicipality <-  "Alamada"

vALA_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vALA_POTypes_tmp <- vALA_POTypes_tmp %>%
  filter(vALA_POTypes_tmp$Region == vRegion, 
         vALA_POTypes_tmp$Province == vProvince,
         vALA_POTypes_tmp$SettlementArea == vSettlementArea,
         vALA_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vALA_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Alamada in North Cotabato with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 3 651 973 632 967 0 0 1283 1940
Farmers Association FA 36 314 200 5 698 0 0 318 216
Irrigators Association IA 2 76 42 0 0 0 0 76 42
Water Users Association WUA 1 29 31 0 0 0 0 29 31
Total: 42 1070 1246 637 1665 0 0 1706 2229
#Libungan
# Make dataframe
vMunicipality <-  "Libungan"

vLIB_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vLIB_POTypes_tmp <- vLIB_POTypes_tmp %>%
  filter(vLIB_POTypes_tmp$Region == vRegion, 
         vLIB_POTypes_tmp$Province == vProvince,
         vLIB_POTypes_tmp$SettlementArea == vSettlementArea,
         vLIB_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vLIB_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Libungan in North Cotabato with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Farmers Association FA 7 146 186 26 19 0 0 146 146
Total: 7 146 186 26 19 0 0 146 146
#Pigcawayan
# Make dataframe
vMunicipality <-  "Pigcawayan"

vPIG_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vPIG_POTypes_tmp <- vPIG_POTypes_tmp %>%
  filter(vPIG_POTypes_tmp$Region == vRegion, 
         vPIG_POTypes_tmp$Province == vProvince,
         vPIG_POTypes_tmp$SettlementArea == vSettlementArea,
         vPIG_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vPIG_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Pigcawayan in North Cotabato with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Farmers Association FA 7 109 117 15 7 4 3 101 113
Water Users Association WUA 1 95 55 0 0 0 0 95 55
Total: 8 204 172 15 7 4 3 196 168
To display a chart illustrating the records of North Cotabato Settlement Area 2 in North Cotabato, Region XII along with the corresponding number of POs using the ggplot command in R.
vNCSA2_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince,
         vLocations_POTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vNCSA2_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 50, by = 10), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vNCSA2_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste(vSettlementArea, "in", vProvince, "with PO Types table"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in North Cotabato, Region XII with SP Types table within the database, you can follow the command below:
vRegion <- "Region XII"
vProvince <- "North Cotabato"
vSettlementArea <- "Sultan Kudarat Settlement Area 1 Phase 2"
vMunicipality <-  "Makilala"

vMAK_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vMAK_MUN_SPTypes_tmp <- vMAK_MUN_SPTypes_tmp %>%
  filter(vMAK_MUN_SPTypes_tmp$Region == vRegion, 
         vMAK_MUN_SPTypes_tmp$Province == vProvince,
         vMAK_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vMAK_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vMAK_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Makilala North Cotabato with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 2 310 300.4082
Farm to Market Road FMR Kms 1 0 12.4200
Post Harvest Facilities PHF Units 2 NA 3.0000
Rural Water Systems RWS HHs 2 0 655.0000
Total: 7 NA 970.8282
vMunicipality <- "Tulunan"

vTUL_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vTUL_MUN_SPTypes_tmp <- vTUL_MUN_SPTypes_tmp %>%
  filter(vTUL_MUN_SPTypes_tmp$Region == vRegion, 
         vTUL_MUN_SPTypes_tmp$Province == vProvince,
         vTUL_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vTUL_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vTUL_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Tulunan North Cotabato with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 2 733 709.9397
Agro-forestry AGRO Has 1 89 484.5400
Crop Intensification CI Has 1 NA 257.0000
Farm to Market Road FMR Kms 2 0 8.6200
Post Harvest Facilities PHF Units 3 NA 4.0000
Rural Water Systems RWS HHs 1 0 620.0000
Total: 10 NA 2084.0997
To display a chart illustrating the records of Municipalities in Davao del Sur, Region XI along with the corresponding number of SPs using the ggplot command in R.
vNC3_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince,
         vLocations_SPTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vNC3_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vNC3_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Municipalities in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Sultan Kudarat Settlement Area 1 Phase 2 in North Cotabato, Region XII table within the database, you can follow the command below:
#Makilala
# Make dataframe
vMunicipality <-  "Makilala"

vMAK_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vMAK_POTypes_tmp <- vMAK_POTypes_tmp %>%
  filter(vMAK_POTypes_tmp$Region == vRegion, 
         vMAK_POTypes_tmp$Province == vProvince,
         vMAK_POTypes_tmp$SettlementArea == vSettlementArea,
         vMAK_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vMAK_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Makilala in North Cotabato with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 2 67 54 12 42 0 0 79 96
Farmers Association FA 13 196 197 1 1 0 0 197 198
Water Users Association WUA 5 226 115 0 0 0 0 226 115
Womens Organization WO 4 0 132 0 0 0 63 0 195
Total: 24 489 498 13 43 0 63 502 604
#Tulunan
# Make dataframe
vMunicipality <-  "Tulunan"

vTUL_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vTUL_POTypes_tmp <- vTUL_POTypes_tmp %>%
  filter(vTUL_POTypes_tmp$Region == vRegion, 
         vTUL_POTypes_tmp$Province == vProvince,
         vTUL_POTypes_tmp$SettlementArea == vSettlementArea,
         vTUL_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vTUL_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Tulunan in North Cotabato with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 1 75 45 0 0 0 0 75 45
Farmers Association FA 18 375 259 31 7 0 0 406 266
Irrigators Association IA 1 21 10 0 0 0 0 21 10
Water Users Association WUA 1 5 2 16 8 0 0 21 10
Womens Organization WO 2 0 60 0 0 0 0 0 60
Total: 23 476 376 47 15 0 0 523 391
To display a chart illustrating the records of Sultan Kudarat Settlement Area 1 Phase 2 in North Cotabato, Region XII along with the corresponding number of POs using the ggplot command in R.
vNCSA1_2_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince,
         vLocations_POTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vNCSA1_2_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 5), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vNCSA1_2_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste(vSettlementArea, "in", vProvince, "with PO Types table"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in South Cotabato, Region XII with SP Types table within the database, you can follow the command below:
vRegion <- "Region XII"
vProvince <- "South Cotabato"
vSettlementArea <- "Ned Settlement Area"
vMunicipality <-  "Lake Sebu"

vLAKE_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vLAKE_MUN_SPTypes_tmp <- vLAKE_MUN_SPTypes_tmp %>%
  filter(vLAKE_MUN_SPTypes_tmp$Region == vRegion, 
         vLAKE_MUN_SPTypes_tmp$Province == vProvince,
         vLAKE_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vLAKE_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vLAKE_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Lake Sebu South Cotabato with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 4 349 337.8100
Agro-forestry AGRO Has 2 78 425.2482
Bridge BRDG Lms 2 0 27.0000
Crop Intensification CI Has 1 NA 810.0000
Farm to Market Road FMR Kms 4 0 22.2900
Irrigation IRRIG Has 3 0 106.0000
Post Harvest Facilities PHF Units 6 NA 8.0000
Rural Water Systems RWS HHs 2 0 210.0000
Total: 24 NA 1946.3482
To display a chart illustrating the records of Municipalities in Davao del Sur, Region XI along with the corresponding number of SPs using the ggplot command in R.
vNED_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince,
         vLocations_SPTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vNED_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vNED_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Municipalities in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Ned Settlement Area in South Cotabato, Region XII table within the database, you can follow the command below:
#Lake Sebu
# Make dataframe
vMunicipality <-  "Lake Sebu"

vLAKE_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vLAKE_POTypes_tmp <- vLAKE_POTypes_tmp %>%
  filter(vLAKE_POTypes_tmp$Region == vRegion, 
         vLAKE_POTypes_tmp$Province == vProvince,
         vLAKE_POTypes_tmp$SettlementArea == vSettlementArea,
         vLAKE_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vLAKE_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Lake Sebu in South Cotabato with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 6 292 218 109 72 12 0 0 0
Irrigators Association IA 3 0 0 0 0 0 0 0 0
Water Users Association WUA 2 31 25 20 29 3 1 3 1
Total: 11 323 243 129 101 15 1 3 1
To display a chart illustrating the records of Ned Settlement Area in South Cotabato, Region XII along with the corresponding number of POs using the ggplot command in R.
vNEDSA_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince,
         vLocations_POTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vNEDSA_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vNEDSA_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste(vSettlementArea, "in", vProvince, "with PO Types table"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Sultan Kudarat, Region XII with SP Types table within the database, you can follow the command below:
vRegion <- "Region XII"
vProvince <- "Sultan Kudarat"
vSettlementArea <- "Sultan Kudarat Settlement Area 1"
vMunicipality <-  "Columbio"

vCOL_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vCOL_MUN_SPTypes_tmp <- vCOL_MUN_SPTypes_tmp %>%
  filter(vCOL_MUN_SPTypes_tmp$Region == vRegion, 
         vCOL_MUN_SPTypes_tmp$Province == vProvince,
         vCOL_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vCOL_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vCOL_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Columbio Sultan Kudarat with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 2 442 428.9653
Agro-forestry AGRO Has 2 74 408.8965
Crop Intensification CI Has 2 150 300.0000
Farm to Market Road FMR Kms 2 0 6.6800
Irrigation IRRIG Has 3 0 657.0000
Post Harvest Facilities PHF Units 1 NA 2.0000
Rural Water Systems RWS HHs 1 0 659.0000
Total: 13 NA 2462.5418
To display a chart illustrating the records of Municipalities in Davao del Sur, Region XI along with the corresponding number of SPs using the ggplot command in R.
vSK1_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince,
         vLocations_SPTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vSK1_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vSK1_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Municipalities in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Sultan Kudarat Settlement Area 1 in Sultan Kudarat, Region XII table within the database, you can follow the command below:
#Columbio
# Make dataframe
vMunicipality <-  "Columbio"

vCOL_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vCOL_POTypes_tmp <- vCOL_POTypes_tmp %>%
  filter(vCOL_POTypes_tmp$Region == vRegion, 
         vCOL_POTypes_tmp$Province == vProvince,
         vCOL_POTypes_tmp$SettlementArea == vSettlementArea,
         vCOL_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vCOL_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Columbio in Sultan Kudarat with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 1 275 331 0 0 0 0 0 0
Farmers Association FA 13 98 37 43 0 9 0 0 0
Irrigators Association IA 4 187 36 0 0 0 0 0 0
Water Users Association WUA 1 72 57 0 0 0 0 0 0
Total: 19 632 461 43 0 9 0 0 0
To display a chart illustrating the records of Sultan Kudarat Settlement Area 1 in Sultan Kudarat, Region XII along with the corresponding number of POs using the ggplot command in R.
vSKSA1_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince,
         vLocations_POTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vSKSA1_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 2), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vSKSA1_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste(vSettlementArea, "in", vProvince, "with PO Types table"), 
       caption="Data Collected by: Junald A. Lagod")

To view the Settlement Areas in Sultan Kudarat, Region XII with SP Types table within the database, you can follow the command below:
vRegion <- "Region XII"
vProvince <- "Sultan Kudarat"
vSettlementArea <- "Sultan Kudarat Settlement Area 2"
vMunicipality <-  "Bagumbayan"

vBAG_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vBAG_MUN_SPTypes_tmp <- vBAG_MUN_SPTypes_tmp %>%
  filter(vBAG_MUN_SPTypes_tmp$Region == vRegion, 
         vBAG_MUN_SPTypes_tmp$Province == vProvince,
         vBAG_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vBAG_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vBAG_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Bagumbayan Sultan Kudarat with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 1 277 268.1033
Agro-forestry AGRO Has 1 26 143.1100
Crop Intensification CI Has 2 NA 786.0000
Farm to Market Road FMR Kms 2 0 13.0500
Post Harvest Facilities PHF Units 3 NA 4.0000
Total: 9 NA 1214.2633
vMunicipality <-  "Palimbang"

vPAL_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vPAL_MUN_SPTypes_tmp <- vPAL_MUN_SPTypes_tmp %>%
  filter(vPAL_MUN_SPTypes_tmp$Region == vRegion, 
         vPAL_MUN_SPTypes_tmp$Province == vProvince,
         vPAL_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vPAL_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vPAL_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Palimbang Sultan Kudarat with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 3 580 563.0170
Agro-forestry AGRO Has 1 37 204.4482
Bridge BRDG Lms 1 0 60.0000
Crop Intensification CI Has 2 NA 250.0000
Farm to Market Road FMR Kms 1 0 9.8000
Post Harvest Facilities PHF Units 6 NA 7.0000
Rural Water Systems RWS HHs 2 NA 641.0000
Total: 16 NA 1735.2652
vMunicipality <-  "Senator Ninoy Aquino"

vSNA_MUN_SPTypes_tmp <- vLocations_SPTypes %>%
  select(-Barangay)

vSNA_MUN_SPTypes_tmp <- vSNA_MUN_SPTypes_tmp %>%
  filter(vSNA_MUN_SPTypes_tmp$Region == vRegion, 
         vSNA_MUN_SPTypes_tmp$Province == vProvince,
         vSNA_MUN_SPTypes_tmp$SettlementArea == vSettlementArea,
         vSNA_MUN_SPTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(SPType, Code, UnitMeasure)  %>%
  summarise(SPs = sum(SPs), 
            Beneficiaries = sum(Beneficiaries), Qty = sum(Qty),
            .groups = 'drop')

results_df <- data.frame(vSNA_MUN_SPTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("SP Type", "Code", 
                       "UnitMeasure", "SPs", 
                       "Beneficiaries", "Qty", 
                       stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, vProvince, "with SP Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first colum
Senator Ninoy Aquino Sultan Kudarat with SP Types table
SP Type Code UnitMeasure SPs Beneficiaries Qty
Agribusiness AGBiz Has 1 277 268.1033
Agro-forestry AGRO Has 2 74 408.0787
Crop Intensification CI Has 3 NA 424.0000
Farm to Market Road FMR Kms 1 0 7.4800
Irrigation IRRIG Has 1 0 36.0000
Post Harvest Facilities PHF Units 5 NA 6.0000
Total: 13 NA 1149.6620
To display a chart illustrating the records of Municipalities in Davao del Sur, Region XI along with the corresponding number of SPs using the ggplot command in R.
vSK2_SA_SPTypes_tmp <- vLocations_SPTypes %>%
  filter(vLocations_SPTypes$Region == vRegion, 
         vLocations_SPTypes$Province == vProvince,
         vLocations_SPTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, SPType, Code)  %>%
  summarise(SPs = sum(SPs), .groups = 'drop')

ggplot(vSK2_SA_SPTypes_tmp, aes(x = Code, y = as.integer(SPs), fill=SPType)) +
  geom_col() +
  geom_text(aes(label = as.integer(SPs), y= as.integer(SPs) / 2)) + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#AABB22", "#EEFF77",
                               "#BACCC1", "#3C8D53", 
                               "#BE2A3E", "#3388DD", 
                               "#CC11BB", "#EC754A", 
                               "#AAFF23")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vSK2_SA_SPTypes_tmp) + 
  xlab("SP Types") + ylab("Number of SPs")  +
  labs(title= paste("Municipalities in", vProvince, vRegion, "and SP Types w/ No. of SPs"),  
       caption="Data Collected by: Junald A. Lagod")

To view the Sultan Kudarat Settlement Area 2 in Sultan Kudarat, Region XII table within the database, you can follow the command below:
#Bagumbayan
# Make dataframe
vMunicipality <-  "Bagumbayan"

vBAG_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vBAG_POTypes_tmp <- vBAG_POTypes_tmp %>%
  filter(vBAG_POTypes_tmp$Region == vRegion, 
         vBAG_POTypes_tmp$Province == vProvince,
         vBAG_POTypes_tmp$SettlementArea == vSettlementArea,
         vBAG_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vBAG_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Bagumbayan in Sultan Kudarat with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 1 77 62 11 10 0 0 0 0
Farmers Association FA 11 252 167 130 59 2 1 0 0
Total: 12 329 229 141 69 2 1 0 0
#Palimbang
# Make dataframe
vMunicipality <-  "Palimbang"

vPAL_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vPAL_POTypes_tmp <- vPAL_POTypes_tmp %>%
  filter(vPAL_POTypes_tmp$Region == vRegion, 
         vPAL_POTypes_tmp$Province == vProvince,
         vPAL_POTypes_tmp$SettlementArea == vSettlementArea,
         vPAL_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vPAL_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Palimbang in Sultan Kudarat with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 1 31 15 0 0 0 0 0 0
Farmers Association FA 4 14 2 27 19 0 0 0 0
Water Users Association WUA 2 0 0 0 0 0 0 0 0
Womens Organization WO 2 0 0 0 0 0 0 0 0
Total: 9 45 17 27 19 0 0 0 0
#Senator Ninoy Aquino
# Make dataframe
vMunicipality <-  "Senator Ninoy Aquino"

vSNA_POTypes_tmp <- vLocations_POTypes %>%
  select( -Barangay) %>%
  drop_na()

vSNA_POTypes_tmp <- vSNA_POTypes_tmp %>%
  filter(vSNA_POTypes_tmp$Region == vRegion, 
         vSNA_POTypes_tmp$Province == vProvince,
         vSNA_POTypes_tmp$SettlementArea == vSettlementArea,
         vSNA_POTypes_tmp$Municipality == vMunicipality)  %>%
  group_by(POType, Code)  %>%
  summarise(POs = sum(POs), ARBMale = sum(ARBMale), ARBFemale = sum(ARBFemale),
            NonARBMale = sum(NonARBMale), NonARBFemale = sum(NonARBFemale), 
            IPMale = sum(IPMale), IPFemale = sum(IPFemale),
            NonIPMale = sum(NonIPMale), NonIPFemale = sum(NonIPFemale), 
            .groups = 'drop')

results_df <- data.frame(vSNA_POTypes_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("PO Type", "Code", "POs", "ARB Male", "ARB Female", 
                       "Non-ARB Male", "Non-ARB Female", "IP Male", "IP Female", 
                       "Non-IP Male", "Non-IP Female", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = paste(vMunicipality, "in", vProvince, "with PO Types table"), booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Senator Ninoy Aquino in Sultan Kudarat with PO Types table
PO Type Code POs ARB Male ARB Female Non-ARB Male Non-ARB Female IP Male IP Female Non-IP Male Non-IP Female
Cooperative COOP 3 200 120 0 0 0 0 0 0
Farmers Association FA 12 724 202 17 0 0 0 299 14
Irrigators Association IA 1 22 6 0 0 0 0 0 0
Womens Organization WO 6 0 448 0 116 0 0 0 0
Total: 22 946 776 17 116 0 0 299 14
To display a chart illustrating the records of Sultan Kudarat Settlement Area 2 in Sultan Kudarat, Region XII along with the corresponding number of POs using the ggplot command in R.
vSKSA2_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vRegion, 
         vLocations_POTypes$Province == vProvince,
         vLocations_POTypes$SettlementArea == vSettlementArea)  %>%
  group_by(Municipality, POType, Code)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vSKSA2_POTypes_tmp, aes(x = Code, y = as.integer(POs), fill=POType)) +
  geom_col() +
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(~Municipality, scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vSKSA2_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste(vSettlementArea, "in", vProvince, "with PO Types table"), 
       caption="Data Collected by: Junald A. Lagod")

To retrieve a list of covered Municipalities records along with the corresponding number of ARCs and Barangays
To view the Municipalities table within the database, you can follow the command below:
vLocations_ARCs_tmp <- vLocations_ARCs %>%
  select(-ARC) %>%
  group_by(Region, Province, Settlement, Municipality, MunCode)%>%
  summarise(ARCs = sum(ARCs), .groups = 'drop')

vLocations_BRGYS_tmp <- vLocations_BRGYS %>%
  select(-Barangay) %>%
  group_by(Region, Province, Settlement, Municipality, MunCode)%>%
  summarise(Barangays = sum(Barangays), .groups = 'drop')


vMunicipalities <- merge(vLocations_ARCs_tmp, vLocations_BRGYS_tmp)
vMunicipalities_tmp <- vMunicipalities

# Make dataframe
results_df <- data.frame(vMunicipalities_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("Region", "Province", "Settlement", "Municipality", "Code", "No. of ARCs", "No. of Barangays", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Covered Municipalities table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Covered Municipalities table
Region Province Settlement Municipality Code No. of ARCs No. of Barangays
Region X Bukidnon Kadingilan Settlement Area Kadingilan KAD 2 7
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Kolambugan KOL 1 8
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 1 24
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Maigo MAI 1 4
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Munai MUN 0 6
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Pantao Ragat PAN 1 8
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN 1 18
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tubod TUB 1 3
Region X Lanao del Norte Lanao del Norte Settlement Area 2 Sapad SAP 1 6
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN 1 25
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Sultan Naga Dimaporo SND 1 3
Region XI Davao de Oro Karagan Valley Settlement Area Maragusan MAR 0 3
Region XI Davao de Oro Karagan Valley Settlement Area New Bataan NEW 0 1
Region XI Davao del Sur B’laan Settlement Area Magsaysay MAG2 0 6
Region XI Davao del Sur B’laan Settlement Area Matanao MAT 0 13
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN 2 20
Region XII North Cotabato North Cotabato Settlement Area 1 Carmen CAR 1 8
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA 1 19
Region XII North Cotabato North Cotabato Settlement Area 2 Libungan LIB 0 6
Region XII North Cotabato North Cotabato Settlement Area 2 Pigcawayan PIG 0 5
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Makilala MAK 1 13
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL 1 15
Region XII South Cotabato Ned Settlement Area Lake Sebu LAKE 0 1
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL 0 18
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Bagumbayan BAG 0 7
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Palimbang PAL 0 3
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA 0 20
Total: 17 270
To display a chart illustrating the records of Municipalities along with the corresponding number of ARCs and Barangays using the ggplot command in R.
vLocations_ARCs_tmp <- vLocations_ARCs_tmp %>%
  mutate(Location='ARCs')
vLocations_BRGYS_tmp <- vLocations_BRGYS_tmp %>%
  mutate(Location='Barangays')

vMunicipalities_initial <- data.frame(vLocations_ARCs_tmp)
vMunicipalities <- vMunicipalities_initial
vMunicipalities[(nrow(vMunicipalities) + 1):(nrow(vMunicipalities) + 
                                               nrow(vLocations_BRGYS_tmp)),] <- vLocations_BRGYS_tmp

ggplot(data=vMunicipalities, aes(x=Municipality, y=as.integer(ARCs), fill=factor(Location))) +
  geom_bar(position="dodge",stat="identity") + 
  coord_flip() +
  scale_y_continuous(
    breaks = seq(0, 30, by = 2), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="Covered Areas")) +
  xlab("Municipalities") + ylab("Number of ARCs and Barangays") + 
  labs(title= "Covered Municipalities with Number of ARCs and Barangays", 
       caption="Data Collected by: Junald A. Lagod")  

To retrieve a list of covered Barangays records along with the corresponding number of Sub-Projects
To view the Barangays table within the database, you can follow the command below:
vLocBarangays_tmp <- vLocations_BRGYS %>%
  select(-RegCode, -ProvCode, -SACode, -Barangays)
  
# Make dataframe
results_df <- data.frame(vLocBarangays_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("Region", "Province", "Settlement", "Municipality", "Code", "Barangay Name", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Covered Barangays table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Covered Barangays table
Region Province Settlement Municipality Code Barangay Name
Region X Bukidnon Kadingilan Settlement Area Kadingilan KAD Pinamangguan
Region X Bukidnon Kadingilan Settlement Area Kadingilan KAD Matampay
Region X Bukidnon Kadingilan Settlement Area Kadingilan KAD Mabuhay
Region X Bukidnon Kadingilan Settlement Area Kadingilan KAD Kibalagon
Region X Bukidnon Kadingilan Settlement Area Kadingilan KAD Cabadiangan
Region X Bukidnon Kadingilan Settlement Area Kadingilan KAD Balaoro
Region X Bukidnon Kadingilan Settlement Area Kadingilan KAD Bagongbayan
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Kolambugan KOL Sucodan
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Kolambugan KOL Small Banisilon
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Kolambugan KOL Pantaon
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Kolambugan KOL Palao
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Kolambugan KOL Lumbac
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Kolambugan KOL Inudaran
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Kolambugan KOL Caromatan
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Kolambugan KOL Bubong
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Upper Caningag (Taguitingan)
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Tombador
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Tipaan
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Tawinian
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Tambacon
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Talambo
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Somiorang
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Rarab
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Poblacion (Bago-A-Ingud)
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Pelingkingan
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Pangao
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Olango
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Mapantao
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Malabaogan
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Lumbac
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Lubo
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Lower Caningag (Perimbangan)
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Lemoncret
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Lamigadato
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Ilihan
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Durianon
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Daan Campo
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Baguiguicon
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Magsaysay MAG1 Babasalon
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Maigo MAI Poblacion
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Maigo MAI Mentring
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Maigo MAI Maliwanag
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Maigo MAI Inoma
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Munai MUN Cadayonan
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Munai MUN Tambo
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Munai MUN Pantao-Munai
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Munai MUN Pantao
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Munai MUN Maganding
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Munai MUN Madaya
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Pantao Ragat PAN Poblacion
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Pantao Ragat PAN Tangcal
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Pantao Ragat PAN Pantao Marug
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Pantao Ragat PAN Pansor
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Pantao Ragat PAN Matampay
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Pantao Ragat PAN Culubun
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Pantao Ragat PAN Cabasagan
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Pantao Ragat PAN Banday
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Tangcal Proper
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Somiorang
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Small Meladoc
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Small Banisilon
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Punod
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Poona Kapatagan
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Poblacion
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Pelingkingan
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Papan
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Lingco-an
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Lindongan
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Linao
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Lamaosa
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Bubong
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Big Meladoc
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Big Banisilon
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Berwar
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tangcal TAN Bayabao
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tubod TUB Palao
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tubod TUB Dalama
Region X Lanao del Norte Lanao del Norte Settlement Area 1 Tubod TUB Bualan
Region X Lanao del Norte Lanao del Norte Settlement Area 2 Sapad SAP Poblacion
Region X Lanao del Norte Lanao del Norte Settlement Area 2 Sapad SAP Pili
Region X Lanao del Norte Lanao del Norte Settlement Area 2 Sapad SAP Lower Sapad
Region X Lanao del Norte Lanao del Norte Settlement Area 2 Sapad SAP Gamal
Region X Lanao del Norte Lanao del Norte Settlement Area 2 Sapad SAP Dansalan
Region X Lanao del Norte Lanao del Norte Settlement Area 2 Sapad SAP Baning
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Taraka
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Songgod
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Rebucon
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Raraban
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Rarab
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Poblacion
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Petadun
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Paride
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Pantar
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Panganapan
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Notongan
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Masibay
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Mangan
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Malaig
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Lupitan
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Liangan
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Katubuan
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Kaludan
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Inayawan
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Dimayon
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Carcum
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Canibongan
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Cabasaran (Laya)
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Bangko
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Nunungan NUN Abaga
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Sultan Naga Dimaporo SND Rebucon
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Sultan Naga Dimaporo SND Dalama
Region X Lanao del Norte Lanao del Norte Settlement Area 3 Sultan Naga Dimaporo SND Bangco
Region XI Davao de Oro Karagan Valley Settlement Area Maragusan MAR Cheng Shihan
Region XI Davao de Oro Karagan Valley Settlement Area Maragusan MAR Langgawisan
Region XI Davao de Oro Karagan Valley Settlement Area Maragusan MAR Bahi
Region XI Davao de Oro Karagan Valley Settlement Area New Bataan NEW Andap
Region XI Davao del Sur B’laan Settlement Area Magsaysay MAG2 Tagaytay
Region XI Davao del Sur B’laan Settlement Area Magsaysay MAG2 San Miguel
Region XI Davao del Sur B’laan Settlement Area Magsaysay MAG2 Malawanit
Region XI Davao del Sur B’laan Settlement Area Magsaysay MAG2 Glamang
Region XI Davao del Sur B’laan Settlement Area Magsaysay MAG2 Balnate
Region XI Davao del Sur B’laan Settlement Area Magsaysay MAG2 Bacungan
Region XI Davao del Sur B’laan Settlement Area Matanao MAT Towak
Region XI Davao del Sur B’laan Settlement Area Matanao MAT Tamlangon
Region XI Davao del Sur B’laan Settlement Area Matanao MAT Saub
Region XI Davao del Sur B’laan Settlement Area Matanao MAT Saboy
Region XI Davao del Sur B’laan Settlement Area Matanao MAT New Katipunan
Region XI Davao del Sur B’laan Settlement Area Matanao MAT Manga
Region XI Davao del Sur B’laan Settlement Area Matanao MAT Kapok
Region XI Davao del Sur B’laan Settlement Area Matanao MAT Dongan-Pekong
Region XI Davao del Sur B’laan Settlement Area Matanao MAT Colonsabak
Region XI Davao del Sur B’laan Settlement Area Matanao MAT Cabasagan
Region XI Davao del Sur B’laan Settlement Area Matanao MAT Bangkal
Region XI Davao del Sur B’laan Settlement Area Matanao MAT Asinan
Region XI Davao del Sur B’laan Settlement Area Matanao MAT Asbang
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Wadya
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Tumbao-Camalig
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Tinimbakan
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Thailand
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Salama
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Puting-bato
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Poblacion 2
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Poblacion 1
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Pinamulaan
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Paradise
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Pantar
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Miguel Macasarte
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Malinao
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Malagap
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Kiaring
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Kalawaig
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Gastav
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Carugmanan
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Capayangan
Region XII North Cotabato North Cotabato Settlement Area 1 Banisilan BAN Busaon
Region XII North Cotabato North Cotabato Settlement Area 1 Carmen CAR Ma Kwok Ming
Region XII North Cotabato North Cotabato Settlement Area 1 Carmen CAR Tambad
Region XII North Cotabato North Cotabato Settlement Area 1 Carmen CAR Palanggalan
Region XII North Cotabato North Cotabato Settlement Area 1 Carmen CAR Malapag
Region XII North Cotabato North Cotabato Settlement Area 1 Carmen CAR Macabenban
Region XII North Cotabato North Cotabato Settlement Area 1 Carmen CAR Liliongan
Region XII North Cotabato North Cotabato Settlement Area 1 Carmen CAR Cadiis
Region XII North Cotabato North Cotabato Settlement Area 1 Carmen CAR Bentangan
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Lu Xiaoming
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Laura Scott
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Upper Dado
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Raradangan
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Rangayen
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Polayagan
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Pigcawaran
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Paruayan
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Pacao
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Mirasol
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Mapurok
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Malitubog
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Macabasa
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Lower Dado
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Kitacubong
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Guiling
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Camansi
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Barangiran
Region XII North Cotabato North Cotabato Settlement Area 2 Alamada ALA Bao
Region XII North Cotabato North Cotabato Settlement Area 2 Libungan LIB Nicholas Ortiz
Region XII North Cotabato North Cotabato Settlement Area 2 Libungan LIB Sinapangan
Region XII North Cotabato North Cotabato Settlement Area 2 Libungan LIB Palao
Region XII North Cotabato North Cotabato Settlement Area 2 Libungan LIB Kitubod
Region XII North Cotabato North Cotabato Settlement Area 2 Libungan LIB Kiloyao
Region XII North Cotabato North Cotabato Settlement Area 2 Libungan LIB Cabpangi
Region XII North Cotabato North Cotabato Settlement Area 2 Pigcawayan PIG Renibon
Region XII North Cotabato North Cotabato Settlement Area 2 Pigcawayan PIG Payong-Payong
Region XII North Cotabato North Cotabato Settlement Area 2 Pigcawayan PIG Midpapan 2
Region XII North Cotabato North Cotabato Settlement Area 2 Pigcawayan PIG Kimarayang
Region XII North Cotabato North Cotabato Settlement Area 2 Pigcawayan PIG Anick
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Makilala MAK Taluntalunan
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Makilala MAK Villaflores
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Makilala MAK Sto. Nino
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Makilala MAK Sta. Felomina
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Makilala MAK Rodero
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Makilala MAK New Baguio
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Makilala MAK Malungon
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Makilala MAK Malabuan
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Makilala MAK Luayon
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Makilala MAK Kawayanon
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Makilala MAK Guangan
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Makilala MAK Cabilao
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Makilala MAK Bato
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL Tuburan
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL Paraiso
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL New Caridad
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL New Bunawan
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL Nabundasan
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL Maybula
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL Magbok
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL Lampagang
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL Kanibong
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL G. Baynosa
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL Daig
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL Bituan
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL Batang
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL Banayal
Region XII North Cotabato Sultan Kudarat Settlement Area 1 Phase 2 Tulunan TUL Bacong
Region XII South Cotabato Ned Settlement Area Lake Sebu LAKE Ned
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Wada Hikaru
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Anthony Harrison
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Telafas
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Sucob
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Sinapulan
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Polomolok
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Poblacion
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Natividad
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Mayo
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Maligaya
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Makat
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Lomoyon
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Libertad
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Lasak
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Eday
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Datalblao
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Bunawan
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 1 Columbio COL Bantangan
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Bagumbayan BAG Sumilil
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Bagumbayan BAG Santo Nino
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Bagumbayan BAG Monteverde
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Bagumbayan BAG Masiag
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Bagumbayan BAG Kanulay
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Bagumbayan BAG Kabulanan
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Bagumbayan BAG Daluga
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Palimbang PAL Molon
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Palimbang PAL Kalibuhan
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Palimbang PAL Baluan
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Tinalon
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Tacupis
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Sewod
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Nati
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Midtungok
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Malegdeg
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Limuhay
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Langgal
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Lagubang
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Kulaman
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Kuden
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Kiadsam
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Kapatagan
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Kadi
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Gapok
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Buklod
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Bugso
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Buenaflores
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Basag
Region XII Sultan Kudarat Sultan Kudarat Settlement Area 2 Senator Ninoy Aquino SNA Banali
Total:
To display a chart illustrating the records of Barangays in Kadingilan along with the corresponding number of POs using the ggplot command in R.
#Kadingilan
# Make dataframe
vMUN_Region <-  "Region X"
vMUN_Province <-  "Bukidnon"
vMUN_Settlement <-  "Kadingilan Settlement Area"
vMUN_Municipality <-  "Kadingilan"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

To display a chart illustrating the records of Barangays in Lanao del Norte Settlement Area 1 along with the corresponding number of POs using the ggplot command in R.
#Kolambugan
vMUN_Region <-  "Region X"
vMUN_Province <-  "Lanao del Norte"
vMUN_Settlement <-  "Lanao del Norte Settlement Area 1"
vMUN_Municipality <-  "Magsaysay"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#Kolambugan
vMUN_Municipality <-  "Kolambugan"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#Magsaysay
vMUN_Municipality <-  "Magsaysay"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#Maigo
vMUN_Municipality <-  "Maigo"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#Munai
vMUN_Municipality <-  "Munai"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#Pantao Ragat
vMUN_Municipality <-  "Pantao Ragat"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#Tangcal
vMUN_Municipality <-  "Tangcal"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#Tubod
vMUN_Municipality <-  "Tubod"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

To display a chart illustrating the records of Barangays in Lanao del Norte Settlement Area 2 along with the corresponding number of POs using the ggplot command in R.
#Sapad
vMUN_Region <-  "Region X"
vMUN_Province <-  "Lanao del Norte"
vMUN_Settlement <-  "Lanao del Norte Settlement Area 2"
vMUN_Municipality <-  "Sapad"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

To display a chart illustrating the records of Barangays in Lanao del Norte Settlement Area 3 along with the corresponding number of POs using the ggplot command in R.
#Nunungan
vMUN_Region <-  "Region X"
vMUN_Province <-  "Lanao del Norte"
vMUN_Settlement <-  "Lanao del Norte Settlement Area 3"
vMUN_Municipality <-  "Nunungan"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#Sultan Naga Dimaporo
vMUN_Municipality <-  "Sultan Naga Dimaporo"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

To display a chart illustrating the records of Barangays in Karagan Valley Settlement Area along with the corresponding number of POs using the ggplot command in R.
#Maragusan
vMUN_Region <-  "Region XI"
vMUN_Province <-  "Davao de Oro"
vMUN_Settlement <-  "Karagan Valley Settlement Area"
vMUN_Municipality <-  "Maragusan"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#New Bataan
vMUN_Municipality <-  "New Bataan"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

To display a chart illustrating the records of Barangays in B’laan Settlement Area along with the corresponding number of POs using the ggplot command in R.
#Magsaysay
vMUN_Region <-  "Region XI"
vMUN_Province <-  "Davao del Sur"
vMUN_Settlement <-  "B'laan Settlement Area"
vMUN_Municipality <-  "Magsaysay"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#Matanao
vMUN_Municipality <-  "Matanao"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

To display a chart illustrating the records of Barangays in North Cotabato Settlement Area 1 along with the corresponding number of POs using the ggplot command in R.
#Banisilan
vMUN_Region <-  "Region XII"
vMUN_Province <-  "North Cotabato"
vMUN_Settlement <-  "North Cotabato Settlement Area 1"
vMUN_Municipality <-  "Banisilan"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 3) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#Carmen
vMUN_Municipality <-  "Carmen"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

To display a chart illustrating the records of Barangays in North Cotabato Settlement Area 2 along with the corresponding number of POs using the ggplot command in R.
#Alamada
vMUN_Region <-  "Region XII"
vMUN_Province <-  "North Cotabato"
vMUN_Settlement <-  "North Cotabato Settlement Area 2"
vMUN_Municipality <-  "Alamada"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 3) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#Libungan
vMUN_Municipality <-  "Libungan"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#Pigcawayan
vMUN_Municipality <-  "Pigcawayan"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

To display a chart illustrating the records of Barangays in Sultan Kudarat Settlement Area 1 Phase 2 along with the corresponding number of POs using the ggplot command in R.
#Makilala
vMUN_Region <-  "Region XII"
vMUN_Province <-  "North Cotabato"
vMUN_Settlement <-  "Sultan Kudarat Settlement Area 1 Phase 2"
vMUN_Municipality <-  "Makilala"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 2) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#Tulunan
vMUN_Municipality <-  "Tulunan"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 4) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

To display a chart illustrating the records of Barangays in Ned Settlement Area along with the corresponding number of POs using the ggplot command in R.
#Lake Sebu
vMUN_Region <-  "Region XII"
vMUN_Province <-  "South Cotabato"
vMUN_Settlement <-  "Ned Settlement Area"
vMUN_Municipality <-  "Lake Sebu"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

To display a chart illustrating the records of Barangays in Sultan Kudarat Settlement Area 1 along with the corresponding number of POs using the ggplot command in R.
#Columbio
vMUN_Region <-  "Region XII"
vMUN_Province <-  "Sultan Kudarat"
vMUN_Settlement <-  "Sultan Kudarat Settlement Area 1"
vMUN_Municipality <-  "Columbio"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

To display a chart illustrating the records of Barangays in Sultan Kudarat Settlement Area 2 along with the corresponding number of POs using the ggplot command in R.
#Bagumbayan
vMUN_Region <-  "Region XII"
vMUN_Province <-  "Sultan Kudarat"
vMUN_Settlement <-  "Sultan Kudarat Settlement Area 2"
vMUN_Municipality <-  "Bagumbayan"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#Palimbang
vMUN_Region <-  "Region XII"
vMUN_Province <-  "Sultan Kudarat"
vMUN_Settlement <-  "Sultan Kudarat Settlement Area 2"
vMUN_Municipality <-  "Palimbang"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 5) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

#Senator Ninoy Aquino
vMUN_Region <-  "Region XII"
vMUN_Province <-  "Sultan Kudarat"
vMUN_Settlement <-  "Sultan Kudarat Settlement Area 2"
vMUN_Municipality <-  "Senator Ninoy Aquino"

vBRGYS_POTypes_tmp <- vLocations_POTypes %>%
  filter(vLocations_POTypes$Region == vMUN_Region, 
         vLocations_POTypes$Province == vMUN_Province,
         vLocations_POTypes$SettlementArea == vMUN_Settlement,
         vLocations_POTypes$Municipality == vMUN_Municipality)  %>%
  group_by(Municipality, POType, Code, Barangay)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vBRGYS_POTypes_tmp, aes(x = Barangay, y = as.integer(POs), fill=factor(POType))) +
  geom_col(position="dodge") + 
  coord_flip() +  
  scale_y_continuous(
    breaks = seq(0, 30, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  geom_text(aes(label = as.integer(POs), y = as.integer(POs) / 2),
            position = position_dodge(width = 1 , preserve = "total"), size = 3) +
  guides(fill=guide_legend(title="")) + 
  theme(legend.position = "bottom") +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A", "#ABC123", 
                               "#EACF65", "#3C8D53", "#FFF123", "#BACCC1")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vBRGYS_POTypes_tmp) + 
  xlab("PO Types") + ylab("Number of POs")  +
  labs(title= paste("Barangays in", vMUN_Municipality, 
                    ",", vMUN_Province, "and PO Types with No. of POs"), 
       caption="Data Collected by: Junald A. Lagod")

To retrieve a list of Major Status records along with the corresponding number of Detailed Status.
This SQL query uses a JOIN operation to combine the Major Status table with the Municipalities table based on a shared MajorStatusID_FK. It then calculates the count of ProjStatusID_PK for each Major Status using the COUNT function and aliases it as ‘Number Of Detailed Status’. The GROUP BY clause ensures that the count is calculated per Major Status. By executing this query, you will retrieve a result set that includes the Major Status records along with the corresponding number of Detailed Status for each Major Status, you can use the following SQL statement:
vMajorStatus <- dbGetQuery(con, 'SELECT
                                    projentities.EntityID_PK AS MajorStatusID, 
                                    projentities.EntityName AS MajorStatus, 
                                    projstatus.Component, 
                                    Count(projstatus.ProjStatusID_PK) AS DetailedStatus
                                FROM
                                    projentities
                                    INNER JOIN
                                    projstatus
                                    ON 
                                        projstatus.MajorStatusID_FK = projentities.EntityID_PK
                                WHERE
                                    GroupCategory = "Status Category"
                                GROUP BY
                                    projentities.EntityID_PK, 
                                    projentities.EntityID_PK, 
                                    projentities.EntityName, 
                                    projstatus.Component
                                ORDER BY
                                    projstatus.Component ASC, 
                                    projentities.EntityID_PK ASC;')
To view the Major Status table within the database, you can follow the command below:
vMajorStatus_no_ID <- vMajorStatus %>%
  select(-MajorStatusID)#To hide columns in the table

# Make dataframe
results_df <- data.frame(vMajorStatus_no_ID, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("Major Status", "Component", "Detailed Status", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Major Status table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Major Status table
Major Status Component Detailed Status
Pre-Implementation AAAD/INFRA 2
Actual-Implementation AAAD/INFRA 3
Post-Implementation AAAD/INFRA 2
Actual-Implementation INSTI 9
Total: 16
To display a chart illustrating the records of Major Status along with the corresponding Detailed Status using the ggplot command in R.
vMajorStatus_with_ID <- vMajorStatus %>%
  select(MajorStatusID)#To show hide columns in the table

ggplot(vMajorStatus, aes(x = Component, y = as.integer(DetailedStatus), fill=Component)) +
  geom_col() +
  geom_text(aes(label = as.integer(DetailedStatus), y=as.integer(DetailedStatus)/ 2)) +
  scale_y_continuous(
    breaks = seq(0, 10, by = 1), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="Detailed Status")) + 
  scale_fill_manual(values = c("#3C8D53", "#EC754A")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_wrap(facets =~reorder(MajorStatus, MajorStatusID), scales = "free_x", drop = TRUE) +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vMajorStatus) + 
  xlab("Major Status") + ylab("Number of Detailed Status")  +
  labs(title= "Major Status with Number of Detailed Status",  
       caption="Data Collected by: Junald A. Lagod")

To retrieve a list of Detailed Status records for INSTI along with the corresponding number of POs
This SQL query uses a JOIN operation to combine the Detailed Status table with the POs table based on a shared POID_PK It then calculates the count of POID_FK for each Detailed Status using the COUNT function and aliases it as ‘Number Of POs’. The GROUP BY clause ensures that the count is calculated per Detailed Status. By executing this query, you will retrieve a result set that includes the Detailed Status records along with the corresponding number of POs for each Municipality area, you can use the following SQL statement:
To view the Detailed Status for INSTITUTIONAL DEVELOPMENT table within the database, you can follow the command below:
#Organizational Capacity
vPOTypeStatus_OCR_tmp <- vPOTypeStatus %>%
  filter(vPOTypeStatus$Component == "INSTI", vPOTypeStatus$Rating == "Organizational Capacity")%>%
  group_by(MajorStatus, Rating, Status)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

# Make dataframe
results_df <- data.frame(vPOTypeStatus_OCR_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("Major Status", "Rating", "Detailed Status", "No. of PO Group", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Organizational Capacity Status table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Organizational Capacity Status table
Major Status Rating Detailed Status No. of PO Group
Actual-Implementation Organizational Capacity Highly Operational 104
Actual-Implementation Organizational Capacity Not Operational 5
Actual-Implementation Organizational Capacity Not yet assessed 70
Actual-Implementation Organizational Capacity Operational 170
Total: 349
#*******************************------------------------------------------------------------------------------------------------
#Enterprise Readiness
vPOTypeStatus_ERR_tmp <- vPOTypeStatus %>%
  filter(vPOTypeStatus$Component == "INSTI", vPOTypeStatus$Rating == "Enterprise Readiness")%>%
  group_by(MajorStatus, Rating, Status)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

# Make dataframe
results_df <- data.frame(vPOTypeStatus_ERR_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("Major Status", "Rating", "Detailed Status", "No. of PO Group", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Enterprise Readiness Status table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Enterprise Readiness Status table
Major Status Rating Detailed Status No. of PO Group
Actual-Implementation Enterprise Readiness Highly Ready 59
Actual-Implementation Enterprise Readiness Not Ready 53
Actual-Implementation Enterprise Readiness Not yet assessed 70
Actual-Implementation Enterprise Readiness Ready 167
Total: 349
#*******************************------------------------------------------------------------------------------------------------
#Maturity Level
vPOTypeStatus_MLR_tmp <- vPOTypeStatus %>%
  filter(vPOTypeStatus$Component == "INSTI", vPOTypeStatus$Rating == "Maturity Level")%>%
  group_by(MajorStatus, Rating, Status)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

# Make dataframe
results_df <- data.frame(vPOTypeStatus_MLR_tmp, stringsAsFactors = FALSE)

# Sum the last row of each column if numeric 
func <- function(z) if (is.numeric(z)) sum(z) else '' 
sumrow <- as.data.frame(lapply(results_df, func))

# Give name to the first element of the new data frame created above
sumrow[1] <- "Total:"

# Add the original and new data frames together
summed_results_df <- rbind(results_df, sumrow)

# Name the columns
colnames <- data.frame("Major Status", "Rating", "Detailed Status", "No. of PO Group", stringsAsFactors = FALSE)
colnames(summed_results_df) <- colnames

# Make Table
kable(summed_results_df, caption = "Maturity Level Status table", booktabs = TRUE) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
  row_spec(dim(summed_results_df)[1], bold = T) %>% # format last row
  column_spec(1, italic = T) # format first column
Maturity Level Status table
Major Status Rating Detailed Status No. of PO Group
Actual-Implementation Maturity Level Functional 98
Actual-Implementation Maturity Level Not Functional 171
Actual-Implementation Maturity Level Not yet assessed 80
Total: 349
To display a chart illustrating the records of Detailed Status for INSTI along with the corresponding number of POs using the ggplot command in R.
vPOTypeStatus <- union(vPOTypeStatus_OCR, vPOTypeStatus_ERR)
vPOTypeStatus <- union(vPOTypeStatus, vPOTypeStatus_MLR)
vPOTypeStatus <- vPOTypeStatus %>%
  group_by(Component, MajorStatus, Rating, StatusID, Status)  %>%
  summarise(POs = sum(POs), .groups = 'drop')

ggplot(vPOTypeStatus, aes(x = str_wrap(Status, width = 10) , y = as.integer(POs), fill=reorder(Status, StatusID))) +
  geom_col() +  
  geom_text(aes(label = as.integer(POs), y= as.integer(POs) / 2)) + 
  scale_y_continuous(
    breaks = seq(0, 200, by = 50), 
    expand = c(0, 0), # The horizontal axis does not extend to either side
  )  +
  guides(fill=guide_legend(title="", position="bottom")) + 
  scale_fill_manual(values = c("#EE754A", "#AABB11", "#3C8D53",  
                               "#EC754A", "#AABB11", "#3C8D53", 
                               "#BE2A3E", "#AABB11", "#EC754A", "#BE2A3E")) +
  # independent x-axis scale in each facet, 
  # drop absent factor levels (not the case here)
  facet_grid(cols = vars(Rating), scales = "free_x", space = "free_x") +
  force_panelsizes(cols = c(1, 1, 1)) +
  theme_bw() +
  # use named character vector to replace x-axis labels
  scale_x_discrete(labels = vPOTypeStatus) + 
  xlab("Detailed Status") + ylab("Number of POs")  +
  labs(title= "Status for Institutional Development with Number of People Organizations (POs)",  
       caption="Data Collected by: Junald A. Lagod")