0
0
R Programmingprogramming~30 mins

Bar plots (geom_bar, geom_col) in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Bar plots with geom_bar and geom_col in R
📖 Scenario: You are working with a small store's sales data. You want to visualize how many items were sold for each product category using bar plots.
🎯 Goal: Create a bar plot using geom_bar and another bar plot using geom_col in R with ggplot2 to show the number of items sold per product category.
📋 What You'll Learn
Create a data frame called sales_data with columns category and items_sold with exact values
Create a variable called bar_plot_geom_bar that uses ggplot with geom_bar(stat = "count") to plot counts of categories
Create a variable called bar_plot_geom_col that uses ggplot with geom_col() to plot items_sold per category
Print both plots using print()
💡 Why This Matters
🌍 Real World
Bar plots are commonly used in business to quickly see how different categories compare in counts or values, such as sales per product type.
💼 Career
Data analysts and data scientists use bar plots to communicate insights clearly to teams and stakeholders.
Progress0 / 4 steps
1
Create the sales data frame
Create a data frame called sales_data with two columns: category containing the values 'Fruits', 'Vegetables', 'Dairy', 'Bakery', and items_sold containing the values 50, 30, 20, 40 respectively.
R Programming
Need a hint?

Use data.frame() with category = c(...) and items_sold = c(...) to create the data frame.

2
Create bar plot using geom_bar
Create a variable called bar_plot_geom_bar that uses ggplot with sales_data as data, mapping category to the x-axis, and add geom_bar(stat = "count") to plot the count of each category.
R Programming
Need a hint?

Use ggplot(sales_data, aes(x = category)) + geom_bar(stat = "count") to create the bar plot.

3
Create bar plot using geom_col
Create a variable called bar_plot_geom_col that uses ggplot with sales_data as data, mapping category to the x-axis and items_sold to the y-axis, and add geom_col() to plot the exact items sold per category.
R Programming
Need a hint?

Use ggplot(sales_data, aes(x = category, y = items_sold)) + geom_col() to create the bar plot with exact values.

4
Print both bar plots
Use print() to display both bar_plot_geom_bar and bar_plot_geom_col plots.
R Programming
Need a hint?

Use print(bar_plot_geom_bar) and print(bar_plot_geom_col) to show the plots.