0
0
R Programmingprogramming~30 mins

Line plots (geom_line) in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Line plots (geom_line)
📖 Scenario: You are a data analyst working with monthly sales data for a small store. You want to create a simple line plot to see how sales change over the months.
🎯 Goal: Build a line plot using geom_line() in R with ggplot2 to visualize monthly sales data.
📋 What You'll Learn
Create a data frame called sales_data with two columns: month and sales with exact values.
Create a variable called plot_title with the exact string 'Monthly Sales Over Time'.
Use ggplot() with geom_line() to create a line plot using sales_data.
Add the title stored in plot_title to the plot using ggtitle().
Print the plot.
💡 Why This Matters
🌍 Real World
Line plots are used to show trends over time, like sales, temperature, or stock prices.
💼 Career
Data analysts and scientists use line plots to communicate changes and patterns clearly to others.
Progress0 / 4 steps
1
Create the sales data frame
Create a data frame called sales_data with two columns: month and sales. Use these exact values: month as c('Jan', 'Feb', 'Mar', 'Apr', 'May') and sales as c(150, 200, 180, 220, 210).
R Programming
Need a hint?

Use data.frame() to create the data frame with the exact column names and values.

2
Create the plot title variable
Create a variable called plot_title and assign it the string 'Monthly Sales Over Time'.
R Programming
Need a hint?

Assign the exact string to plot_title using the assignment operator <-.

3
Create the line plot with ggplot2
Use ggplot() with sales_data as data. Map month to the x-axis and sales to the y-axis. Add geom_line() to create the line plot. Store the plot in a variable called sales_plot. Then add the title stored in plot_title using ggtitle().
R Programming
Need a hint?

Remember to load ggplot2 with library(ggplot2) before creating the plot.

4
Display the line plot
Print the plot stored in sales_plot to display the line plot.
R Programming
Need a hint?

Use print() to show the plot in the R console or script.