Export data to R
In this walk through you will see how to export data to RStudio and then convert it into the graphs and tables
Last updated
In this walk through you will see how to export data to RStudio and then convert it into the graphs and tables
Last updated
(c) 2024 Data Illusion Zumbrunn. All rights reserved. Reproduction strictly forbidden.
Begin by exporting the respondents' data from NGSurvey in CSV format
In the RStudio use the script to import the CSV file and set up your dataset.
Where:
survey_csv: Variable to store the data.
read.csv: Function to read CSV file.
file: Path to the CSV file.
stringsAsFactors: Convert string columns to factor.
header: Use the first row as column names.
sep: Delimiter used in the file (comma).
Now that your data is loaded into R or RStudio, you can start analyzing it and creating visualizations and tables.
Data Summary: Provides a quick summary of the dataset, including statistics for each column.
Where:
summary: Function to provide basic descriptive statistics for each column in your dataset
survey_csv: Your dataset.
Simple table: For this walk through we have chosen the variable Recommend_likelihood that represents the survey question "How likely are you to recommend our service to a friend or colleague"
Where:
table: This function creates a frequency table.
survey_csv$Recommend_likelihood: This specifies the column Recommend_likelyhood
from the survey_csv
dataset.
Output: The frequency table shows how often each category of recommendation likelihood occurs in the dataset.
Optional: We recommend to ensure the correct ordering of the categorical variable in tables and visualizations.
Where:
factor: Converts the variable to a factor (categorical variable).
levels: Specifies the order of categories for the factor.
Visualization: simple bar chart visualization of the recommendation likelihood distribution.
Create the barplot to visualize the data:
Where:
barplot: Generates a bar chart.
table(survey_csv$Recommend_likelyhood): Creates a frequency table for the bar heights.
main: Sets the title of the plot.
xlab: Label for the x-axis.
ylab: Label for the y-axis.
col: Sets the bar color to light blue.
las = 2: Rotates axis labels to be perpendicular for better readability.
cex.names = 0.8: Reduces the size of the bar labels to prevent overlap.
Optional: Adjust margins and label positions for the barplot.
Where:
par: Sets graphical parameters.
mar: Adjusts plot margins: bottom, left, top, right (increased bottom margin to avoid overlap).
+ 0.1: Slightly increases each plot margin to ensure extra space for plot elements, preventing them from being clipped or overcrowded.
mgp: Controls the placement of axis title, labels, and line. Here, 4
shifts the x-axis label further down.