0
0
R Programmingprogramming~5 mins

Scatter plots (geom_point) in R Programming

Choose your learning style9 modes available
Introduction

A scatter plot shows how two things relate by drawing dots for each pair of values. It helps us see patterns or connections between two sets of numbers.

When you want to see if two measurements are connected, like height and weight.
To check if one thing changes when another thing changes, like study time and test scores.
When you want to spot groups or clusters in your data.
To find if there are any unusual points that don’t fit the pattern.
When you want to compare two sets of numbers visually.
Syntax
R Programming
ggplot(data) + geom_point(mapping = aes(x = x_variable, y = y_variable))

data is your dataset.

aes() tells which columns to use for x and y axes.

Examples
Plot car weight (wt) on x-axis and miles per gallon (mpg) on y-axis.
R Programming
ggplot(mtcars) + geom_point(aes(x = wt, y = mpg))
Plot sepal length vs sepal width for iris flowers.
R Programming
ggplot(iris) + geom_point(aes(x = Sepal.Length, y = Sepal.Width))
Plot horsepower (hp) against quarter mile time (qsec).
R Programming
ggplot(mtcars) + geom_point(aes(x = hp, y = qsec))
Sample Program

This program creates a scatter plot showing how car weight relates to fuel efficiency using dots.

R Programming
library(ggplot2)

# Use the built-in mtcars dataset
# Plot weight vs miles per gallon
plot <- ggplot(mtcars) +
  geom_point(aes(x = wt, y = mpg))

print(plot)
OutputSuccess
Important Notes

You need to have the ggplot2 package installed to use geom_point().

Scatter plots work best with continuous numeric data on both axes.

You can add colors or shapes to points to show more information.

Summary

Scatter plots use dots to show relationships between two numeric variables.

geom_point() is the function in ggplot2 to make scatter plots.

They help find patterns, clusters, or unusual points in data.