# R code to display the barplot of number of OCV agaist the count as per county 
library(readxl)
ACTIVE <- read_excel("D:/PERIS/ACTIVE.xlsx")
ACTIVE
## # A tibble: 64,162 × 57
##    cbo_id cbo          ward_id ward  consituency_id constituency countyid county
##     <dbl> <chr>          <dbl> <chr>          <dbl> <chr>           <dbl> <chr> 
##  1   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
##  2   7306 CHEER UP PR…     911 Kiuu             162 Ruiru              22 Kiambu
##  3   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
##  4   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
##  5   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
##  6   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
##  7   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
##  8   7306 CHEER UP PR…     911 Kiuu             162 Ruiru              22 Kiambu
##  9   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
## 10   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
## # ℹ 64,152 more rows
## # ℹ 49 more variables: cpims_ovc_id <dbl>, ovc_names <chr>, gender <chr>,
## #   dob <chr>, date_of_birth <chr>, age <dbl>, age_at_reg <dbl>,
## #   agerange <chr>, birthcert <chr>, bcertnumber <chr>, ovcdisability <chr>,
## #   ncpwdnumber <chr>, ovchivstatus <chr>, artstatus <chr>, facility_id <dbl>,
## #   facility <chr>, facility_mfl_code <dbl>, date_of_linkage <chr>,
## #   ccc_number <chr>, duration_on_art <chr>, viral_load <dbl>, …
number_of_children <- table(ACTIVE$county)
barplot(number_of_children, xlab = "county", ylab = "count", col = "blue", main = "BARPLOT OF NUMBER OF OVC AGAINST THE COUNT")
barplot

barplot

# with or without birth certificate
OVCwith_without_berthcertficate <- table(ACTIVE$birthcert)
barplot(OVCwith_without_berthcertficate, xlab = "Birth certificate status", ylab = "count", main = "BARPLOT OF OVC WITH AND WITHOUT BIRTH CERTIFICATE", col = "red")
barplot

barplot

# with or without HIV
with_without_HIV_ovc <- table(ACTIVE$ovchivstatus)
barplot(with_without_HIV_ovc, xlab = "HIV status", ylab = "count", col = "green", main = "BARPLOT TO SHOW OVC WITH/WITHOUT HIV")
barplot

barplot

# barplot to show the age range of OVC
age_range <- table(ACTIVE$agerange)
barplot(age_range, xlab = "Age range", ylab = "count", col = "skyblue", main = "BARPLOT OF OVC AGE RANGE AGAINST COUNT")
barplot

barplot

library(readxl)
ACTIVE <- read_excel("D:/PERIS/ACTIVE.xlsx")
ACTIVE
## # A tibble: 64,162 × 57
##    cbo_id cbo          ward_id ward  consituency_id constituency countyid county
##     <dbl> <chr>          <dbl> <chr>          <dbl> <chr>           <dbl> <chr> 
##  1   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
##  2   7306 CHEER UP PR…     911 Kiuu             162 Ruiru              22 Kiambu
##  3   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
##  4   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
##  5   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
##  6   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
##  7   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
##  8   7306 CHEER UP PR…     911 Kiuu             162 Ruiru              22 Kiambu
##  9   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
## 10   7306 CHEER UP PR…     912 Mwiki            162 Ruiru              22 Kiambu
## # ℹ 64,152 more rows
## # ℹ 49 more variables: cpims_ovc_id <dbl>, ovc_names <chr>, gender <chr>,
## #   dob <chr>, date_of_birth <chr>, age <dbl>, age_at_reg <dbl>,
## #   agerange <chr>, birthcert <chr>, bcertnumber <chr>, ovcdisability <chr>,
## #   ncpwdnumber <chr>, ovchivstatus <chr>, artstatus <chr>, facility_id <dbl>,
## #   facility <chr>, facility_mfl_code <dbl>, date_of_linkage <chr>,
## #   ccc_number <chr>, duration_on_art <chr>, viral_load <dbl>, …
ovcdisability<-table(ACTIVE$ovcdisability)
ovcdisability
## 
## HAS DISABILITY  NO DISABILITY 
##            147          64015
barplot(ovcdisability, ylab = "Count", ylim = c(0, max(ovcdisability) + 5000), 
        beside = TRUE, col = c("blue", "red"), names.arg = levels(ACTIVE$ovcdisability),
        main = "Counts of Disability",
        args.legend = list(title = "Disability Type"))

# Add counts on the bars
text(x = barplot(ovcdisability, plot = FALSE), y = ovcdisability/2, labels = ovcdisability, pos = 3, cex = 0.9, col = "black")
barplot

barplot

library(readxl)
caregiverhivstatus<-table(ACTIVE$caregiverhivstatus)
caregiverhivstatus
## 
##         HEI NOT KNOWN HIV Test Not Required              NEGATIVE 
##                    15                     8                  6079 
##             NOT KNOWN              POSITIVE 
##                  1258                 54174
# Sample data based on the counts you provided
caregiverhivstatus <- c("HEI NOT KNOWN", "HIV Test Not Required", "NEGATIVE", "NOT KNOWN", "POSITIVE")
counts <- c(15, 8, 6079, 1258, 54174)

# Create a bar plot with counts displayed inside the bars using rainbow colors
barplot(counts, names.arg = caregiverhivstatus,xlab = "care giver hiv status", ylab = "Count", col = rainbow(length(counts)),
        main = "Caregiver HIV Status")

# Add counts inside the bars
text(x = 1:length(caregiverhivstatus), y = counts/2, labels = counts, pos = 3, cex = 0.9, col = "black")
barplot

barplot

library(readxl)
schoollevel<-table(ACTIVE$schoollevel)
schoollevel
## 
##          ECDE Not in School       Primary     Secondary      Tertiary 
##          6978         10838         30755         15500            82 
##    University 
##             9
# Sample data based on the counts you provided
education_levels <- c("ECDE","Not in School", "Primary", "Secondary", "Tertiary", "University")
counts <- c(6978, 10838, 30755, 15500, 82, 9)

# Create a bar plot with counts displayed inside the bars using rainbow colors
barplot(counts, names.arg = education_levels,xlab = "Education level", ylab = "Count", col = rainbow(length(counts)),
        main = "Education Levels")

# Add counts inside the bars
text(x = 1:length(education_levels), y = counts/2, labels = counts, pos = 3, cex = 0.7, col = "black")
barplot

barplot

immunization<-table(ACTIVE$immunization)
immunization
## 
## Fully Immunized   Not Completed   Not Immunized       Not Known 
##            5398           10571             166           48027
# Sample data based on the counts you provided
immunization_status <- c("Fully Immunized", "Not Completed", "Not Immunized", "Not Known")
counts <- c(5398, 10571, 166, 48027)

# Create a bar plot with counts displayed inside the bars using rainbow colors
barplot(counts, names.arg = immunization_status,xlab = "imunization status", ylab = "Count", col = rainbow(length(counts)),
        main = "Immunization Status")

# Add counts inside the bars
text(x = 1:length(immunization_status), y = counts/2, labels = counts, pos = 3, cex = 0.9, col = "black")
#denis project
library(ggplot2)
barplot

barplot

library(readxl)
library(gplots)
## 
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
## 
##     lowess
# Read data from Excel files
Cpara <- read_excel("D:/DENIS/Cpara.xlsx")
CasePlan <- read_excel("D:/DENIS/CasePlan.xlsx")
ListOfOvcServed <- read_excel("D:/DENIS/ListOfOvcServed.xlsx")
## Warning: Expecting logical in AN2096 / R2096C40: got '2020-05-20'
## Warning: Expecting logical in AO2096 / R2096C41: got 'Not Traceable'
## Warning: Expecting logical in AN2097 / R2097C40: got '2020-05-20'
## Warning: Expecting logical in AO2097 / R2097C41: got 'Not Traceable'
## Warning: Expecting logical in AN2098 / R2098C40: got '2020-05-20'
## Warning: Expecting logical in AO2098 / R2098C41: got 'Not Traceable'
## Warning: Expecting logical in AN2099 / R2099C40: got '2021-11-22'
## Warning: Expecting logical in AO2099 / R2099C41: got 'Ineligible'
## Warning: Expecting logical in AN2100 / R2100C40: got '2021-11-22'
## Warning: Expecting logical in AO2100 / R2100C41: got 'Ineligible'
## Warning: Expecting logical in AN2101 / R2101C40: got '2021-11-22'
## Warning: Expecting logical in AO2101 / R2101C41: got 'Ineligible'
## Warning: Expecting logical in AN2102 / R2102C40: got '2021-11-28'
## Warning: Expecting logical in AO2102 / R2102C41: got 'Ineligible'
## Warning: Expecting logical in AN2103 / R2103C40: got '2021-11-28'
## Warning: Expecting logical in AO2103 / R2103C41: got 'Ineligible'
## Warning: Expecting logical in AN2104 / R2104C40: got '2021-11-28'
## Warning: Expecting logical in AO2104 / R2104C41: got 'Ineligible'
## Warning: Expecting logical in AN2324 / R2324C40: got '2020-05-22'
## Warning: Expecting logical in AO2324 / R2324C41: got 'Not Traceable'
## Warning: Expecting logical in AN2325 / R2325C40: got '2020-05-22'
## Warning: Expecting logical in AO2325 / R2325C41: got 'Not Traceable'
## Warning: Expecting logical in AN2326 / R2326C40: got '2020-05-22'
## Warning: Expecting logical in AO2326 / R2326C41: got 'Not Traceable'
## Warning: Expecting logical in AN3326 / R3326C40: got '2023-05-19'
## Warning: Expecting logical in AO3326 / R3326C41: got 'Duplicated'
## Warning: Expecting logical in AN3327 / R3327C40: got '2023-05-19'
## Warning: Expecting logical in AO3327 / R3327C41: got 'Duplicated'
## Warning: Expecting logical in AN3328 / R3328C40: got '2023-05-19'
## Warning: Expecting logical in AO3328 / R3328C41: got 'Duplicated'
## Warning: Expecting logical in AN3888 / R3888C40: got '2023-06-07'
## Warning: Expecting logical in AN3889 / R3889C40: got '2023-06-07'
## Warning: Expecting logical in AN3890 / R3890C40: got '2023-06-07'
## Warning: Expecting logical in AN4383 / R4383C40: got '2021-10-06'
## Warning: Expecting logical in AO4383 / R4383C41: got 'Relocation'
## Warning: Expecting logical in AN4384 / R4384C40: got '2021-10-06'
## Warning: Expecting logical in AO4384 / R4384C41: got 'Relocation'
## Warning: Expecting logical in AN4385 / R4385C40: got '2021-10-06'
## Warning: Expecting logical in AO4385 / R4385C41: got 'Relocation'
## Warning: Expecting logical in AN4437 / R4437C40: got '2023-06-22'
## Warning: Expecting logical in AO4437 / R4437C41: got 'Case Plan Achievement'
## Warning: Expecting logical in AN4438 / R4438C40: got '2023-06-22'
## Warning: Expecting logical in AO4438 / R4438C41: got 'Case Plan Achievement'
## Warning: Expecting logical in AN4439 / R4439C40: got '2023-06-22'
## Warning: Expecting logical in AO4439 / R4439C41: got 'Case Plan Achievement'
ACTIVE <- read_excel("D:/DENIS/ACTIVE.xlsx")

# Find common IDs
common_ids <- intersect(intersect(Cpara$cpims_ovc_id, CasePlan$cpims_ovc_id), ListOfOvcServed$cpims_ovc_id)
registration_with_common_ids1 <- ACTIVE[ACTIVE$cpims_ovc_id %in% common_ids, ]
ids_without_common_data2 <- ACTIVE[!ACTIVE$cpims_ovc_id %in% common_ids, ]

# Create a data frame with all IDs
all_ids <- rbind(data.frame(Status = "Has cpara, caseplan, OVCserved", registration_with_common_ids1),
                 data.frame(Status = "Has NO cpara, caseplan, OVCserved", ids_without_common_data2))

# Create a custom color palette for the bars
colors <- c("blue", "green")

# Create the bar plot
p <- ggplot(all_ids, aes(x = Status, fill = Status)) +
  geom_bar(color = "black") +
  geom_text(stat = 'count', aes(label = after_stat(count)), vjust = -0.5) +  # Add count labels
  scale_fill_manual(values = colors) +  # Apply custom colors
  labs(title = "Counts of cpims_ovc_id with and without cpara, caseplan, OVCserved",
       x = "Status", y = "Count")

print(p)
barplot

barplot