- Interpret different types of visualizations to gain insights.
- Understand how to apply visualization to different data analysis tasks.
Part 1: Loading and Exploring Data**
Before we start creating plots, we need to load and inspect the datasets we’ll be working with. We’ll use a new dataset called educational_data.csv.
Task 1: Load the educational_data.csv dataset and inspect its structure. This will help you understand what variables you’re working with.
Reflect & Respond
Question 1: What Catches Your Eye? As you browse through the dataset, what stands out to you? Is there anything that piques your curiosity? Maybe a surprising trend or a pattern you didn’t expect?
The first thing that stands out to me is how the max is 104.26 for attendance rate.. That should not be possible, so there might be some issues with the attendance portion of the data. It doesn’t seem like high study hours or even quiz scores lead to a high final grade in this data.
Question 2: What Questions Do You Have? Is there something specific you’d like to dig deeper into? Think about what you might want to learn more about. Are there any relationships between variables you’re curious about?
I would like to dig deeper into the relationships between a few variables and the final grade variable. I would like to view the correlations between most of the data in accordance to the final grade.
Question 3: What’s Your Analytics Game Plan? How would you approach analyzing this dataset? What steps would you take to uncover the insights you’re interested in?
I would visualize the data to see outliers, trends, and patterns. Using a few different visuals we can then get a good grasp on the data. From there I would run some simple statistics and go from there.
Part 2: Visualizing Relationship and Scatter Plots
Scatter plots are useful for visualizing the relationship between two continuous variables. The gg in ggplot stands for “Grammar of Graphics,” which means we build plots in layers.
Scatter Plot
Task 2: Create a scatter plot to explore the relationship between Study_hours and Quiz_Score. This plot will help you visualize if there’s a correlation.
# Create a scatter plot of Study_hours vs. Quiz_Score with a regression lineggplot(data3, aes(x = Study_Hours, y = Quiz_Score)) +# TYPE YOUR CODE. TWO VARIABLES HEREgeom_point(color ="blue", size =3, alpha =0.6) +geom_smooth(method ="lm", color ="red", se =TRUE) +# This line will add a linear regression linelabs(title ="Scatter Plot of Study Hours vs. Quiz_Score", #UPDATE YOUR PLOT TITLESx ="Study Hours (Hours)",y ="Quiz_Score") +theme_minimal() +theme(plot.title =element_text(size =16, face ="bold", hjust =0.5),axis.title.x =element_text(size =12, face ="bold"),axis.title.y =element_text(size =12, face ="bold") )
`geom_smooth()` using formula = 'y ~ x'
Task 3: Now that we’ve visualized the relationship, let’s compute the correlation between the two variables to get a numerical value for their relationship. The use = "complete.obs" argument handles any missing values by only using the rows that have data for both variables.
# Compute the correlation# COMPLETE YOUR CODE BELOWcorrelation <-cor(data3$Study_Hours, data3$Quiz_Score, use ="complete.obs")# Display the correlationcorrelation
[1] -0.04308071
Reflect & Respond
Question: What does the correlation value tell you about the relationship between study hours and quiz scores?
Looking at this data, studying seems to have a minor, negative correlation. One could use this to decide that studying is bad for quiz scores, or at least overstudying may lead to lower scores. More analysis would be needed.
Activity: Customize the Scatterplot
# Create a scatterplot of 'Quiz_Score' vs 'Final_Exam_Score'ggplot(data3, aes(x =Quiz_Score , y = Final_Exam_Score)) +#COMPLETE THE CODEgeom_point(color ="red") +labs(title ="Scatter plot ", x ="x-", y ="y")
Let’s customize the relationship between Quiz_Score and ‘Final_Exam_Score’.
Change the size of the points to make them more prominent. You can also experiment with different shapes (e.g., circles, triangles, squares) Hint: add ‘size = 3, shape = 16’ inside geom_point(). Numbers can change.
Add a linear regression line to your scatter plot to see the trend between variable 1 and variable 2. *Hint: Use geom_smooth()
Update the title and the axis labels. Make the title bold and center it.
Use facet_wrap() to create separate scatter plots based on Gender. *Hint:facet_wrap()
Exercise with the {scatterplot-activity} chunk below.
# Create a scatterplot of 'Quiz_Score' vs 'Final_Exam_Score'# COMPLETE THE CODEggplot(data3, aes(x = Quiz_Score, y = Final_Exam_Score)) +geom_point(color ="blue",size =3, shape =16) +labs(title ="Scatterplot of ", x ="Quiz_Scores", y ="Final_Exam_Score")+geom_smooth(method ="lm", color ="lightpink", se =FALSE)+theme(plot.title =element_text(size =16, face ="bold", hjust =0.5))+facet_wrap(~Gender)
`geom_smooth()` using formula = 'y ~ x'
Part 3: Histogram
Histograms are used to visualize the distribution of a single continuous variable. Let’s create a histogram of Homework_completion.
# TYPE YOUR CODE FOR THE X VARIABLE BELOWggplot(data3, aes(x = Homework_Completion)) +geom_histogram(binwidth =5, fill ="blue", color ="black") +labs(title ="Histogram of ---", x ="---", y ="Frequency") #update your titles
Activity: Customize the Histogram
Change the fill and color of the bars to something else. You can choose any colors you like! Use the link provided earlier for color options. color names
Change the binwidth, and observe how the histogram changes. What happens if you set it to different numbers?
Update the title and the x-axis to something that is relevant to your analytics.
Apply the theme_minimal() and see how it changes the look of your plot. Try out other themes like theme_classic() or theme_dark(). *Hint - You can add +theme_minimal() at the end of the code line.
Add a vertical line at the mean of the variable to highlight the average value. Use geom_vline(). The mean() function with na.rm = TRUE will ignore missing values.
Use facet_wrap() to create separate scatterplots ffor a categorical variable like Gender. For example, if you want two scatterplots based on ‘Gender’ variable, the syntax is +facet_wrap(~Gender).
Use the histogram-activity chunk below to practice.
# Customize the histogram of the 'Homework_completion' variable# COMPLETE THE CODEggplot(data3, aes(x = Homework_Completion)) +geom_histogram(binwidth =4, fill ="blue", color ="black") +labs(title ="", x ="Homework_Completion", y ="Frequency")+theme(plot.title =element_text(size =16, face ="bold", hjust =0.5))+theme_dark()+geom_vline(aes(xintercept =mean(Homework_Completion, na.rm =TRUE)),color ="red", linetype ="dashed", size =1)
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
Part 4: Exploring Grouped Data with Box Plots
Boxplots are useful for visualizing the distribution of a variable across different categories and identifying potential outliers.
Box Plot
Let’s create a box plot of Homework_Completionby Gender.
# Create a boxplot of 'Homework_Completion' by 'Gender'# COMPLETE THE CODEggplot(data3, aes(x = Gender, y = Homework_Completion, fill = Gender)) +geom_boxplot() +labs(title ="Boxplot of ---", x ="Gender", y ="Homework_Completion")
Activity: Customize the Boxplot
Change the fill colors for the boxes.
Add color = “black” (or some other color) to the geom_boxplot() to set the color of the box outlines.
Update the title and the y-axis label properly. Make the title bold and center it. **Hint: ** Add +theme(plot.title = element_text(size = 16, face = "bold", hjust = 0.5))
Customize the outliers by changing their shape and color. For example, make outliers larger and red by adding +geom_boxplot(outlier.colour = "red", outlier.shape = 16, outlier.size = 3)
Use the boxplot-activity chunk below to practice.
# Create a boxplot of 'Homework_Completion' by 'Gender'# COMPLETE THE CODEggplot(data3, aes(x = Gender, y = Homework_Completion, fill = Gender)) +geom_boxplot(color ='black') +labs(title ="Boxplot of", x ="Gender", y ="Homework_Completion")+theme(plot.title =element_text(size =16, face ="bold", hjust =0.5))+theme(legend.position ="none")+geom_boxplot(outlier.colour ="red", outlier.shape =16, outlier.size =3 )
Part 5: Counting Categories with Bar Plots
Bar plots can display the counts of different categories in your data.
Task 5: Visualize the count of students by Gender.
# Create a bar plot of counts of 'Gender'# COMPLETE THE CODE BELOWggplot(data3, aes(x = Gender)) +geom_bar(fill ="green", color ="black") +labs(title ="Bar Plot", x ="Gender", y ="???")
Activity: Customize the Bar Plot
Change the fill color of the bars.
Change the width of the bars by using the width parameter inside geom_bar(). (i.e., width = 0.5)
Update the title and the y-axis labels to be descriptive. Make the title bold and center it.
Use the barplot-activity chunk below to practice.
# Create a bar plot of counts of 'Gender'# COMPLETE THE CODEggplot(data3, aes(x = Gender)) +geom_bar(width =0.5, fill ="blue", color ="black") +labs(title ="Bar Plot of ", x ="Gender", y ="Amount")+#line below was causing errors.#geom_bar(aes(fill = Gender), color = "black") +theme(axis.text.x =element_text(angle =90, hjust =1))+scale_fill_manual(values =c("F"="Female", "M"="Male"))+theme(plot.title =element_text(size =16, face ="bold", hjust =0.5))
Warning: No shared levels found between `names(values)` of the manual scale and the
data's fill values.
Part 6: Tracking Trends with Line Plots
Line plots are useful for showing trends over time or accross ordered categories.
For this, we will use a new dataset, student_quiz_scores.csv from our data folder.
Line Plot
Task 6: Load the student_quiz_scores.csv file and create a line plot to visualize each student’s score trend across quizzes.
# Import/load the datasetdata3_2 <-read_csv("data/student_quiz_scores.csv") # COMPLETE YOUR CODE
Rows: 400 Columns: 3
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): Student_ID, Quiz
dbl (1): Score
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Create a line plot for each student's quiz scoresggplot(data3_2, aes(x = Quiz, y = Score, group = Student_ID, color = Student_ID)) +geom_line(size =1, alpha =0.6) +geom_point(size =2) +labs(title ="Title Name", x ="x", y ="y") +theme_minimal() +theme(plot.title =element_text(size =16, face ="bold", hjust =0.5),axis.title.x =element_text(size =12, face ="bold"),axis.title.y =element_text(size =12, face ="bold"),axis.text.x =element_text(angle =45, hjust =1),legend.position ="none" )
Activity: Customize the Line Plot
Select a subset of 5 specific students to create a more focused line plot.
Make the line thicker and the points larger to improve readability.
Update the plot title and axis labels to be more descriptive. Make the title bold and center it.
Use the lineplot-activity chunk below to practice.
# COMPLETE YOUR CODEselected_students <- data3_2 %>%filter(Student_ID %in%c("Student_1", "Student_3", "Student_5", "Student_7", "Student_9"))ggplot(selected_students, aes(x = Quiz, y = Score, group = Student_ID, color = Student_ID)) +geom_line(size =0.9, alpha =0.6) +geom_point(size =2) +labs(title ="", x ="", y ="") +theme_minimal() +theme(plot.title =element_text(size =17, face ="bold", hjust =0.5),axis.title.x =element_text(size =12, face ="bold"),axis.title.y =element_text(size =12, face ="bold"),axis.text.x =element_text(angle =45, hjust =1),legend.position ="none" )
Final Reflection : How can we use LA in instructional design and decision?
After practicing the basic analysis and visualization techniques for the past couple of weeks, take some time to reflect on how these skills can be applied in the real world.
Consider the role of an educator, instructional designer, curriculum developer, policymaker, etc. How might the ability to analyze and visualize data help you make informed decisions, improve learning outcomes, or design more effective educational experiences? Think broadly about the implications of these skills in your current or future professional context, and share your thoughts on how data-driven insights could enhance your work.
As an educator, you can use the ability to analyze and visualize data to do a couple of things. Depending on when the data was gathered, you could perform a general “check” of the class using visualization. You would also be able to group/regroup students together if your class utilizes grouping. You can also use data from previous years to adjust teaching methods, styles, or material to help the students. In general, analyzing and visualizing data can help us turn guesses into educated decisions. ## Render & Submit
Congratulations, you’ve completed the module!
To receive full score, you will need to render this document and publish via a method such as: Quarto Pub, Posit Cloud, RPubs , GitHub Pages, or other methods. Once you have shared a link to you published document with me and I have reviewed your work, you will be officially done with the current module.
Complete the following steps to submit your work for review by:
First, change the name of the author: in the YAML header at the very top of this document to your name. The YAML header controls the style and feel for knitted document but doesn’t actually display in the final output.
Next, click the “Render” button in the toolbar above to “render” your R Markdown document to a HTML file that will be saved in your R Project folder. You should see a formatted webpage appear in your Viewer tab in the lower right pan or in a new browser window. Let me know if you run into any issues with rendering.
Finally, publish. To do publish, follow the step from the link
If you have any questions about this module, or run into any technical issues, don’t hesitate to contact me.
Once I have checked your link, you will be notified!