0
0
R Programmingprogramming~30 mins

ggplot() and aes() basics in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Basic Plot with ggplot() and aes() in R
📖 Scenario: You are a data analyst who wants to visualize the relationship between two variables in a small dataset. You will create a simple scatter plot using ggplot() and aes() from the ggplot2 package in R.
🎯 Goal: Build a scatter plot using ggplot() and aes() to map variables to the x and y axes.
📋 What You'll Learn
Create a data frame called data with two numeric columns: height and weight with exact values
Create a ggplot object using ggplot() with data as the data source
Use aes() inside ggplot() to map height to the x-axis and weight to the y-axis
Add geom_point() to display the points
Print the plot object to display the scatter plot
💡 Why This Matters
🌍 Real World
Creating visualizations helps understand data patterns and relationships quickly, which is useful in reports and presentations.
💼 Career
Data analysts and scientists use ggplot2 to create clear and attractive charts to communicate insights effectively.
Progress0 / 4 steps
1
Create the data frame
Create a data frame called data with two columns: height containing the values 150, 160, 170, 180, 190 and weight containing the values 65, 70, 75, 80, 85.
R Programming
Need a hint?

Use data.frame() with height = c(...) and weight = c(...) to create the data.

2
Create the ggplot object with aes()
Create a variable called plot and assign it the result of ggplot() with data as the data source and aes() mapping height to x and weight to y.
R Programming
Need a hint?

Use ggplot(data, aes(x = height, y = weight)) and assign it to plot.

3
Add points to the plot
Add geom_point() to the plot object to show the data points. Update plot by adding + geom_point().
R Programming
Need a hint?

Add + geom_point() to the ggplot call to show points.

4
Display the plot
Print the plot object to display the scatter plot.
R Programming
Need a hint?

Use print(plot) to show the plot.