Factor in analysis and plotting
📖 Scenario: You are working with a small dataset of fruit preferences collected from a group of people. Each person chose their favorite fruit from a list. You want to analyze how many people chose each fruit and then create a simple bar plot to visualize the counts.
🎯 Goal: Build a program that creates a factor variable for fruit preferences, counts how many times each fruit was chosen, and then plots these counts in a bar chart.
📋 What You'll Learn
Create a vector called
fruits with the exact values: "apple", "banana", "apple", "orange", "banana", "banana", "apple".Convert the
fruits vector into a factor called fruit_factor.Use the
table() function on fruit_factor to count the number of each fruit and store it in fruit_counts.Create a bar plot of
fruit_counts with the title "Fruit Preferences".💡 Why This Matters
🌍 Real World
Analyzing survey data where answers are categories, like favorite fruits, colors, or brands.
💼 Career
Data analysts and scientists often work with categorical data and need to summarize and visualize it clearly.
Progress0 / 4 steps