This R script is designed to analyze survey (Likert-scale) data from an SPSS file and generate a PowerPoint presentation with a bar chart on each slide. It creates a presentation for each group in the data (e.g., children, adolescents, adults, etc.) For each question, it creates a double bar chart comparing the responses of one group to all the other groups combined.
- R (and SPSS) installed.
- Prepare the SPSS data file:
- Ensure that your SPSS data file has a structure similar to "example_data_file_SPSS.sav".
- The graphs will be automatically created based on the labels, values, etc. defined in SPSS, so properly setting up the SPSS file is crucial.
- Create new titles for each question, add questions as labels, define values (e.g., for "Group": 1 = children, etc.), set missing values to -999.
- Place your SPSS data file in the same directory as the R script.
- Open the R script using your preferred R IDE, such as R-studio.
- Customize the script to suit your specific data:
- Values that need to be adapted are always shown in the code with # ***** ADAPT THIS VALUE *****
- Replace
"your_data_file.sav"with your SPSS data file's name. - Substitute
-999with your data's actual placeholder for missing values, if it differs. - Alter
"your_group_variable"to reflect the variable name representing groups within your data. - Update the
questionsvector with your survey's actual question variable names. - In the
switchstatement, adjust theshort_titlemapping to set short titles for each PowerPoint slide. - Modify section names and their corresponding question counts as necessary.
- Set the
ppt_file_nameprefix to your desired output file name.
- Executing the script will process each group within the data, generating a PowerPoint presentation for each.
- Generated PowerPoint files will be saved in the same directory as the R script, following the naming convention
"your_output_prefix_[group_label].pptx". - Monitor the console for any messages or warnings that might arise during the script's execution.
- The appearance of the bar charts can be tailored by modifying the
create_bar_chartfunction. This includes adjustments to colors, fonts, sizes, etc. - For changes to the PowerPoint slides' layout or design, refer to the
officerpackage documentation and modify the relevant sections of the script accordingly.
