Good morning from the Philippines.
I am working on a survey data and encountered a couple of concerns.
-
I need to rename several variables. I did it using names() command. Is there a “shorter” way especially on multiple variables?
-
I must plot the number of facilities per level and per province. There are three levels (1,2,3) and coded as 0 (No) and 1 (Yes). I converted the levels into numeric and yet I’m not getting the right results.
AFHF_raw ← import(here(“data”, “Encoding sheet for JPARAP Monitoring.xlsx”)) %>%
clean_names() %>%
filter(x1!=“Province”) %>%
select (-x4)
#list of facilities
unique(AFHF_raw$Facility)
#Renaming multiple variables
names(AFHF_raw)[3] = “Operations”
names(AFHF_raw)[4] = “Type_Facility”
names(AFHF_raw)[5] = “Others_Facility”
names(AFHF_raw)[6] = “Hosp_Function”
names(AFHF_raw)[7] = “Trained_ARH”
names(AFHF_raw)[8] = “Foundational course”
names(AFHF_raw)[9] = “AJA”
names(AFHF_raw)[10] = “ADEPT”
names(AFHF_raw)[11] = “HYO”
names(AFHF_raw)[12] = “Others”
names(AFHF_raw)[13] = “AFHF Certified”
names(AFHF_raw)[14] = “Level1”
names(AFHF_raw)[15] = “Level2”
names(AFHF_raw)[16] = “Level3”
names(AFHF_raw)[18] = “DemandGen Activities”
names(AFHF_raw)[19] = “H_Q4(2023)_1014-M”
names(AFHF_raw)[20] = “H_Q1(2024)_1014-M”
names(AFHF_raw)[21] = “H_Q4(2023)_1014-F”
names(AFHF_raw)[22] = “H_Q1(2024)_1014-F”
names(AFHF_raw)[23] = “H_Q4(2023)-Q1(2024)_1014”
names(AFHF_raw)[24] = “H_Q4(2023)-1519_M”
names(AFHF_raw)[25] = “H_Q1(2024)-1519_M”
names(AFHF_raw)[26] = “H_Q4(2023)-1519_F”
names(AFHF_raw)[27] = “H_Q1(2024)-1519_F”
names(AFHF_raw)[28] = “H_Q4(2023)-Q1(2024)_1519”
names(AFHF_raw)[29] = “HM_Q4(2023)_1014-M”
names(AFHF_raw)[30] = “HM_Q1(2024)_1014-M”
names(AFHF_raw)[31] = “HM_Q4(2023)_1014-F”
names(AFHF_raw)[32] = “HM_Q1(2024)_1014-F”
names(AFHF_raw)[33] = “HM_Q4(2023)-Q1(2024)_1014”
names(AFHF_raw)[34] = “HM_Q4(2023)-1519_M”
names(AFHF_raw)[35] = “HM_Q1(2024)-1519_M”
names(AFHF_raw)[36] = “HM_Q4(2023)-1519_F”
names(AFHF_raw)[37] = “HM_Q1(2024)-1519_F”
names(AFHF_raw)[39] = “W/Recordingtool”
names(AFHF_raw)[40] = “Recordingtool”
names(AFHF_raw)[41] = “PAS_1st”
names(AFHF_raw)[42] = “PAS_2ndinitiatives”
names(AFHF_raw)[43] = “PAS_Techguidanceleaders”
names(AFHF_raw)[44] = “PAS_policies”
names(AFHF_raw)[45] = “PAS_perfaudit”
names(AFHF_raw)[46] = “PAS_2ndinitiatives”
#missing values
AFHF_raw[is.na(AFHF_raw)] ← 0
AFHF_clean ← AFHF_raw %>%
mutate_at(c(“H_Q4(2023)_1014-M”,
“H_Q1(2024)_1014-M”,
“H_Q4(2023)_1014-F”,
“H_Q1(2024)_1014-F”,
“H_Q4(2023)-Q1(2024)_1014”,
“H_Q4(2023)-1519_M”,
“H_Q1(2024)-1519_M”,
“H_Q4(2023)-1519_F”,
“H_Q1(2024)-1519_F”,
“H_Q4(2023)-Q1(2024)_1519”,
“HM_Q4(2023)_1014-M”,
“HM_Q1(2024)_1014-M”,
“HM_Q4(2023)_1014-F”,
“HM_Q1(2024)_1014-F”,
“HM_Q4(2023)-Q1(2024)_1014”,
“HM_Q4(2023)-1519_M”,
“HM_Q1(2024)-1519_M”,
“HM_Q4(2023)-1519_F”,
“HM_Q1(2024)-1519_F”,
“HM_Q4(2023)-Q1(2024)_1519”,
“AFHF Certified”,
“Level1”,
“Level2”,
“Level3”),
as.numeric)
#create new column as total of those counselled on HEEADDSSS
AFHF_clean ← AFHF_clean %>%
mutate(HEEADDSSS_counselled = H_Q4(2023)-Q1(2024)_1014
+
H_Q4(2023)-Q1(2024)_1519
)
#create new column as total of those counselled AND managed on HEEADDSSS
AFHF_clean ← AFHF_clean %>%
mutate(HEEADDSSS_counselledNDmanaged = HM_Q4(2023)-Q1(2024)_1014
+
HM_Q4(2023)-Q1(2024)_1519
)
#AFHF Level
AFHF_long ← AFHF_clean %>%
adorn_totals(“col”, select = c(Level1,Level2,Level3)) %>%
pivot_longer(
cols = Level1:Level3,
names_to = “Level”,
values_to = “No”) %>%
mutate(Level=ifelse(Level== “Level1”, “1”, Level)) %>%
mutate(Level=ifelse(Level== “Level2”, “2”, Level)) %>%
mutate(Level=ifelse(Level== “Level3”, “3”, Level)) %>%
filter(No==“1”) #there are no Level2 and Level3 facilities for now
#Number of facilities per level and per province
ggplot(AFHF_long, aes(x = Level, y = No, fill = Province)) +
geom_bar(aes(x = Level, y = No, fill = Province), stat = “identity”, position = “dodge”) +
facet_wrap(~Province, scales = “free_y”, nrow = 4) +
labs(title = “Number and Level Facilities Visited, Samar and Southern Leyte”,
x = “Level”,
y = “Number of Facilities”) +
scale_y_continuous() +
theme_bw()
*Below is my data:
dput(head(AFHF_clean))
structure(list(Province = c(“Samar”, “Samar”, “Southern Leyte”,
“Southern Leyte”, “Southern Leyte”, “Southern Leyte”), Facility = c(“Samar Provincial Hospital”,
“Catbalogan City Teen Center”, “Maasin City Health Unit I”, “Maasin City Health Unit II”,
“Maasin City Health Unit III”, “Macrohon RHU”), Operations = c(“Mon-Fri, 8-5”,
“Adolescent (Wed-Thu, 1-4pm)\r\nFamily Planning (Mon-Tues-Fri)”,
“Mon-Fri, 8-5”, “Mon-Fri, 8-5”, “Tue & Wed 8-5pm”, “Mon-Fri, 8-5”
), Type_Facility = c(“3”, “2”, “2”, “2”, “2”, “1”), Others_Facility = c(“0”,
“0”, “0”, “0”, “0”, “0”), Hosp_Function = c(“1”, “0”, “0”, “0”,
“0”, “0”), Trained_ARH = c(“1”, “1”, “1”, “1”, “1”, “1”), Foundational course
= c(“1”,
“1”, “1”, “1”, “1”, “1”), AJA = c(“1”, “0”, “1”, “0”, “0”, “0”
), ADEPT = c(“1”, “1”, “1”, “1”, “1”, “1”), HYO = c(“1”, “0”,
“0”, “1”, “1”, “1”), Others = c(“Adolescent MHPSS\r\nUsapang BIBA\r\nFPCBT1 and FPCBT2\r\nPPIUD”,
“FPCBT1”, “FPCBT1, FPCBT2”, “FPCBT1, FPCBT2”, “FPCBT1, FPCBT2”,
“FPCBT 1, FPCBT 2, IIUD, MHPSS, Usapang BIBA”), AFHF Certified
= c(1,
1, 1, 1, 1, 1), Level1 = c(1, 1, 1, 1, 1, 1), Level2 = c(0, 0,
0, 0, 0, 0), Level3 = c(0, 0, 0, 0, 0, 0), Regular_DemandGen = c(“1”,
“1”, “0”, “1”, “1”, “1”), DemandGen Activities
= c(“Buntis Congress and Teenspired (both annually)”,
“Information Booth/Campaign (at least once a month)”, “0”, “HIV and CSE at School and Barangay (as requested by the school or SK)”,
“Healthy Young Ones (Health Education)”, “Youth Development Session (monthly or weekly)”
), H_Q4(2023)_1014-M
= c(4, 6, 5, 12, 18, 0), H_Q1(2024)_1014-M
= c(28,
2, 5, 18, 3, 1), H_Q4(2023)_1014-F
= c(15, 2, 4, 11, 10, 2),
H_Q1(2024)_1014-F
= c(52, 9, 6, 21, 6, 0), H_Q4(2023)-Q1(2024)_1014
= c(99,
19, 20, 62, 37, 3), H_Q4(2023)-1519_M
= c(24, 1, 3, 10,
5, 0), H_Q1(2024)-1519_M
= c(75, 2, 7, 20, 5, 2), H_Q4(2023)-1519_F
= c(87,
17, 8, 12, 5, 4), H_Q1(2024)-1519_F
= c(172, 15, 7, 17,
1, 1), H_Q4(2023)-Q1(2024)_1519
= c(358, 35, 25, 59, 16,
7), HM_Q4(2023)_1014-M
= c(4, 3, 5, 12, 18, 0), HM_Q1(2024)_1014-M
= c(28,
2, 5, 18, 3, 1), HM_Q4(2023)_1014-F
= c(13, 1, 4, 11, 10,
2), HM_Q1(2024)_1014-F
= c(52, 9, 6, 21, 6, 0), HM_Q4(2023)-Q1(2024)_1014
= c(97,
15, 20, 62, 37, 3), HM_Q4(2023)-1519_M
= c(24, 1, 3, 10,
5, 0), HM_Q1(2024)-1519_M
= c(75, 2, 7, 20, 5, 2), HM_Q4(2023)-1519_F
= c(28,
15, 8, 12, 5, 4), HM_Q1(2024)-1519_F
= c(172, 15, 7, 17,
1, 1), HM_Q4(2023)-Q1(2024)_1519
= c(299, 33, 25, 59, 16,
7), W/Recordingtool
= c(“1”, “1”, “1”, “1”, “1”, “1”),
Recordingtool = c(“HEADDSS\r\nAHDP Monthly Accomplishment Report”,
“Adolescent Services Logbook”, “Adolescent Friendly Health Logbook”,
“Adolescent Friendly Health Logbook”, “Adolescent Friendly Health Logbook”,
“Adolescent Friendly Health Logbook”), PAS_1st = c(“0”, “1”,
“1”, “1”, “1”, “1”), PAS_2ndinitiatives = c(“0”, “1”, “1”,
“1”, “1”, “1”), PAS_Techguidanceleaders = c(“0”, “0”, “0”,
“0”, “0”, “0”), PAS_policies = c(“0”, “1”, “1”, “1”, “1”,
“1”), PAS_perfaudit = c(“0”, “0”, “0”, “0”, “0”, “0”), part_4_general_findings_and_recommendations_encode_the_statements_either_in_verbatim_or_summarize_the_points = c(“Process algorithm”,
“FP Caravan (counselling and service provision)\r\nReferral facility (15 BHS for assessment by Apr 2024)”,
“Patient Flow; Directory of referal”, “CHU has good partnership with schools and barangay within the community”,
“Health Education conducted at community”, “Adolescent Service Flow Chart; FP is offered to adolescent regardles pregnant or sexually active, support in demand generation of CSE”
), x48 = c(“Additional staff for PPIUD Training”, “Facility is under construction”,
“Lack of manpower”, “Retired doctor”, “Lack of manpower”,
“None”), x49 = c(“Detection and management of suicidal cases”,
“Process flow on consultation/accessing services”, “Consistency of recording in logbook; EO for update”,
“EO for update”, “Consistency of recording in logbook; EO for update”,
“They should only have one adoslecent logbook for general consultation, abused or sexually violated”
), HEEADDSSS_counselled = c(457, 54, 45, 121, 53, 10), HEEADDSSS_counselledNDmanaged = c(396,
48, 45, 121, 53, 10)), row.names = c(NA, 6L), class = “data.frame”)
I hope you can continue to guide me.
Thank you very much.
Regards,
Echo