4. Frequency tables and horizontal bar graphs (% frequencies) of questions 18, 19, 20, 21, 22
Relevel again
The plot
5. Frequency tables and horizontal bar graphs (% frequencies) of questions: 23, 24, 25
6. Frequency tables and horizontal bar graphs (% frequencies) of questions 26, 27, 28
Housekeeping
Source Code
---title: "2024 Parental Attitudes Latvia"author: "Sergio Uribe"date: "2024-04-17"date-modified: last-modifiedformat: html: toc: truetoc-expand: 3code-fold: truecode-tools: trueeditor: visualexecute: echo: false warning: false message: false---# Packages```{r}# Load required libraries with pacman; installs them if not already installedpacman::p_load(tidyverse, # tools for data science visdat, #NAs janitor, # for data cleaning and tables here, # for reproducible research gtsummary, # for tables likert, scales, lubridate )```# Dataset```{r}df <-read_rds(here("data", "df_clean.rds"))```# Tables## 2. Table 1```{r} df |>select(`1_Age`, `2_Sex`, `3_What is your place of residence?`, `4_In which region do you currently live?`, `5_Monthly income of the family`) |>tbl_summary(type =list(`1_Age`~"continuous",`2_Sex`~"categorical",`3_What is your place of residence?`~"categorical",`4_In which region do you currently live?`~"categorical",`5_Monthly income of the family`~"categorical" ),missing ="no"# Option to handle missing data, set to 'no' to not show missing data percentages ) |>modify_header(label ="**Variable**") |>as_gt() # Convert to gt object for further customization if necessary```## **3. Likert data (q6 - 16)**```{r}df_likert <- df |>select(`6_How would you rate access to information on state-funded dental care for children from the dental clinics?`,`7_How would you rate access to information on state-funded dental care for children from the educational institutions (schools, kindergartens)?`,`8_How would you rate access to information on state-funded dental care for children from the Centre for Disease Prevention and Control?`,`9_How would you rate access to information on state-funded dental care for children from your GP (family doctor)?`,`10_How would you rate access to information on state-funded dental care for children in hospitals?`,`11_How would you rate access to information on state-funded dental care for children in pharmacies?`,`12_How would you rate access to information on state-funded dental care for children from patient organisations or other non-governmental organisations?`,`13_How would you rate access to information on state-funded dental care for children from insurance companies?`,`14_How would you rate access to information on state-funded dental care for children on the internet and social media?`,`15_How would you rate access to information on state-funded dental care for children from the on television and radio?`,`16_How would you rate access to information on state-funded dental care for children from relatives and friends?` ) |># Convert all selected columns to factors with ordered levelsmutate(across(everything(), ~factor(., levels =c("Very poor", "Poor", "Acceptable", "Good", "Very good"), ordered =TRUE)))df_likert <-as.data.frame(df_likert)# clean the titlesdf_likert <- df_likert |>rename_with(~sub(".*_", "", .), .cols =everything()) |>rename_with(~sub("How would you rate access to information on state-funded dental care for children ", "", .), .cols =everything())# Now, create the likert data objectlikert_data <-likert(df_likert)# Plot the datalikert_plot <-plot(likert_data)likert_plot +labs(title ="How would you rate access to information\non state-funded dental care for children...")``````{r}ggsave(here("figures", "likert.pdf"), width =21,height =12,units =c("cm"),dpi =300)``````{r}rm(df_likert, likert_data, likert_plot)```#### Question 17```{r}df <- df %>%mutate(`17_Overall, how do you feel about the availability of information on state-funded dental care for children?`=as.factor(`17_Overall, how do you feel about the availability of information on state-funded dental care for children?`)) %>%mutate(`17_Overall, how do you feel about the availability of information on state-funded dental care for children?`=fct_relevel(`17_Overall, how do you feel about the availability of information on state-funded dental care for children?`,"Very difficult to access", "Difficult to access", "Moderately accessible", "Easily accessible", "Very accessible"))``````{r}# Function to calculate frequencies and plot for a specific questionplot_frequency <-function(question, data) {# Calculating frequency and percentage freq_data <- data %>%count(!!sym(question)) %>%mutate(Percent = n /sum(n) *100)# Generating the plot plot <- freq_data %>%ggplot(aes(x =!!sym(question), y = Percent, fill =as.factor(!!sym(question)))) +geom_bar(stat ='identity') +geom_text(aes(label =sprintf("%.1f%%", Percent)), position =position_stack(vjust =0.5), hjust =1) +coord_flip() +labs(title = question, x ="", y ="Percentage (%)") +theme_minimal() +theme(legend.position ="none", axis.text.x =element_text(angle =45, hjust =1))return(plot)}# Plot for "17_Overall, how do you feel about the availability of information on state-funded dental care for children?"plot_17 <-plot_frequency("17_Overall, how do you feel about the availability of information on state-funded dental care for children?", df)# Print the plotprint(plot_17)``````{r}rm(plot_17, plot_frequency)```## **4. Frequency tables and horizontal bar graphs (% frequencies) of questions 18, 19, 20, 21, 22**### Relevel again```{r}df <- df %>%mutate(`18_Can you financially afford a dentist when your child needs it?`=as.factor(`18_Can you financially afford a dentist when your child needs it?`)) %>%mutate(`18_Can you financially afford a dentist when your child needs it?`=fct_relevel(`18_Can you financially afford a dentist when your child needs it?`,"Never", "Rarely", "Sometimes", "Very often", "Always", "Not applicable to me"))``````{r}df <- df %>%mutate(`19_Can you financially afford to see a hygienist when your child needs it?`=as.factor(`19_Can you financially afford to see a hygienist when your child needs it?`)) %>%mutate(`19_Can you financially afford to see a hygienist when your child needs it?`=fct_recode(`19_Can you financially afford to see a hygienist when your child needs it?`,"Never"="Nekad")) %>%mutate(`19_Can you financially afford to see a hygienist when your child needs it?`=fct_relevel(`19_Can you financially afford to see a hygienist when your child needs it?`,"Never", "Rarely", "Sometimes", "Very often", "Always", "Not applicable to me"))# Check the new factor levels and counts``````{r}df <- df %>%mutate(`21_Has your family ever had financial difficulties because of the cost of children's dental treatment?`=as.factor(`21_Has your family ever had financial difficulties because of the cost of children's dental treatment?`)) %>%mutate(`21_Has your family ever had financial difficulties because of the cost of children's dental treatment?`=fct_relevel(`21_Has your family ever had financial difficulties because of the cost of children's dental treatment?`,"Never", "Rarely", "Sometimes", "Regularly"))``````{r}df <- df %>%mutate(`22_How would you evaluate the statement: In Latvia, the funding allocated from the state budget for dental care for children is sufficient.`=as.factor(`22_How would you evaluate the statement: In Latvia, the funding allocated from the state budget for dental care for children is sufficient.`)) %>%mutate(`22_How would you evaluate the statement: In Latvia, the funding allocated from the state budget for dental care for children is sufficient.`=fct_relevel(`22_How would you evaluate the statement: In Latvia, the funding allocated from the state budget for dental care for children is sufficient.`,"Disagree", "Partly disagree", "No opinion", "Partly agree", "Agree"))```### The plot```{r}# Define the relevant questionsquestions <-c('18_Can you financially afford a dentist when your child needs it?','19_Can you financially afford to see a hygienist when your child needs it?','20_In the last 12 months, has there been a situation when you had to cancel or postpone your child\'s visit to the dentist and/or dental hygienist because of the cost?','21_Has your family ever had financial difficulties because of the cost of children\'s dental treatment?','22_How would you evaluate the statement: In Latvia, the funding allocated from the state budget for dental care for children is sufficient.')# Function to calculate frequencies and plot for a single question# plot_frequency <- function(question, data) {# data |># count(!!sym(question)) |># mutate(Percent = n / sum(n) * 100) |># ggplot(aes(x = !!sym(question), y = Percent, fill = as.factor(!!sym(question)))) +# geom_bar(stat = 'identity') +# geom_text(aes(label = sprintf("%.1f%%", Percent)), position = position_stack(vjust = 0.5), hjust = 1) + # Adding labels inside the bars# coord_flip() +# labs(title = question, x = "", y = "Percentage (%)") +# scale_fill_viridis_d() + # Use a discrete color scale for clarity# theme_minimal() +# theme(legend.position = "none", axis.text.x = element_text(angle = 45, hjust = 1))# }# ---------------plot_frequency <-function(question, data) { data %>%count(!!sym(question)) %>%mutate(Percent = n /sum(n) *100) %>%ggplot(aes(x =!!sym(question), y = Percent, fill =as.factor(!!sym(question)))) +geom_bar(stat ='identity') +geom_text(aes(label =sprintf("%.1f%%", Percent)), position =position_stack(vjust =0.5), hjust =1) +# Adding labels inside the barscoord_flip() +labs(title = question, x ="", y ="Percentage (%)") +theme_minimal() +theme(legend.position ="none", axis.text.x =element_text(angle =45, hjust =1))}# Create plots for each question and store them in a listplots_list <-map(questions, ~plot_frequency(.x, df))# Print the plots one by oneplots_list <-lapply(plots_list, print)``````{r}rm(plot_frequency, plots_list, questions)```## 5. **Frequency tables and horizontal bar graphs (% frequencies) of questions: 23, 24, 25**```{r}# Define the relevant questionsquestions <-c('23_What dental care is available for children in your home/neighbourhood?','24_How long does it take to get a child to a dental care facility with the transport available to you?','25_If your child needs acute care (for pain or inflammation), how accessible is dental care?')# Function to calculate frequencies and plot for a single question# plot_frequency <- function(question, data) {# data |># count(!!sym(question)) |># mutate(Percent = n / sum(n) * 100) |># ggplot(aes(x = !!sym(question), y = Percent, fill = as.factor(!!sym(question)))) +# geom_bar(stat = 'identity') +# geom_text(aes(label = sprintf("%.1f%%", Percent)), position = position_stack(vjust = 0.5), hjust = 1) + # Adding labels inside the bars# coord_flip() +# labs(title = question, x = "", y = "Percentage (%)") +# scale_fill_viridis_d() + # Use a discrete color scale for clarity# theme_minimal() +# theme(legend.position = "none", axis.text.x = element_text(angle = 45, hjust = 1))# }# ---------------plot_frequency <-function(question, data) { data %>%count(!!sym(question)) %>%mutate(Percent = n /sum(n) *100) %>%ggplot(aes(x =!!sym(question), y = Percent, fill =as.factor(!!sym(question)))) +geom_bar(stat ='identity') +geom_text(aes(label =sprintf("%.1f%%", Percent)), position =position_stack(vjust =0.5), hjust =1) +# Adding labels inside the barscoord_flip() +labs(title = question, x ="", y ="Percentage (%)") +theme_minimal() +theme(legend.position ="none", axis.text.x =element_text(angle =45, hjust =1))}# Create plots for each question and store them in a listplots_list <-map(questions, ~plot_frequency(.x, df))# Print the plots one by oneplots_list <-lapply(plots_list, print)``````{r}rm(plot_frequency, plots_list, questions)```## 6. **Frequency tables and horizontal bar graphs (% frequencies) of questions 26, 27, 28**```{r}questions <-c('26_Thinking about overall accessibility, how difficult or easy was it to access state-funded dental care for children in the last 12 months?','27_ow satisfied are you with state-funded dental care for children in general?','28_Would you choose state-funded dental care for your children in the future if the care system remained unchanged?')``````{r}# Function to calculate frequencies and plot for a single question# plot_frequency <- function(question, data) {# data |># count(!!sym(question)) |># mutate(Percent = n / sum(n) * 100) |># ggplot(aes(x = !!sym(question), y = Percent, fill = as.factor(!!sym(question)))) +# geom_bar(stat = 'identity') +# geom_text(aes(label = sprintf("%.1f%%", Percent)), position = position_stack(vjust = 0.5), hjust = 1) + # Adding labels inside the bars# coord_flip() +# labs(title = question, x = "", y = "Percentage (%)") +# scale_fill_viridis_d() + # Use a discrete color scale for clarity# theme_minimal() +# theme(legend.position = "none", axis.text.x = element_text(angle = 45, hjust = 1))# }# ---------------plot_frequency <-function(question, data) { data %>%count(!!sym(question)) %>%mutate(Percent = n /sum(n) *100) %>%ggplot(aes(x =!!sym(question), y = Percent, fill =as.factor(!!sym(question)))) +geom_bar(stat ='identity') +geom_text(aes(label =sprintf("%.1f%%", Percent)), position =position_stack(vjust =0.5), hjust =1) +# Adding labels inside the barscoord_flip() +labs(title = question, x ="", y ="Percentage (%)") +theme_minimal() +theme(legend.position ="none", axis.text.x =element_text(angle =45, hjust =1))}# Create plots for each question and store them in a listplots_list <-map(questions, ~plot_frequency(.x, df))# Print the plots one by oneplots_list <-lapply(plots_list, print)```# Housekeeping```{r}rm(plot_frequency, plots_list, questions, df)```