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

🌐 Load data into RStudio

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.

survey_csv <- read.csv(file="C:/Users/Admin/Downloads/ClientSatisfactionSurvey.csv",stringsAsFactors = TRUE, header=TRUE, sep=",")


  • 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).

📊 Analyzing and Visualizing data in RStudio

Now that your data is loaded into R or RStudio, you can start analyzing it and creating visualizations and tables.

  1. Data Summary: Provides a quick summary of the dataset, including statistics for each column.



  • summary: Function to provide basic descriptive statistics for each column in your dataset

  • survey_csv: Your dataset.

  1. 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"



  • 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.

survey_csv$Recommend_likelihood <- factor(
  levels = c("Very unlikely", "Unlikely", 
  "Neutral", "Likely", "Very likely")


  • factor: Converts the variable to a factor (categorical variable).

  • levels: Specifies the order of categories for the factor.

  1. Visualization: simple bar chart visualization of the recommendation likelihood distribution.

Create the barplot to visualize the data:

  main = "How likely are you to recommend our service to a friend or colleague",
  xlab = "Recommendation Likelihood",
  ylab = "Frequency",
  col = "lightblue",
  las = 2,
  cex.names = 0.8  # Reduces the size of the bar labels


  • 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.

par(mar = c(7, 5, 4, 2) + 0.1, mgp = c(4, 1, 0))


  • 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.

Last updated

(c) 2024 Data Illusion Zumbrunn. All rights reserved. Reproduction strictly forbidden.