Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Creating Scatter Plots | Data Visualization
Data Analysis with R

bookCreating Scatter Plots

Why Use Scatter Plots?

A scatter plot is ideal for:

  • Visualizing relationships between two numerical variables;

  • Detecting patterns, clusters, or outliers;

  • Exploring correlation (positive/negative/none).

Basic Syntax for Scatter Plots in ggplot2

ggplot(data = df, aes(x = variable_x, y = variable_y)) +
  geom_point()

To add group-based color, use: aes(x, y, color = group_var)

Example: Selling Price vs Kilometers Driven

ggplot(df, aes(x = km_driven, y = selling_price)) + 
  geom_point() + 
  labs(title = "Scatter Plot of Selling Price vs. Kilometers Driven",
       x = "Kilometers Driven", 
       y = "Selling Price")

This shows how a car’s usage relates to its price — often revealing depreciation trends.

question mark

Which ggplot2 function creates a scatter plot?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 5

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Awesome!

Completion rate improved to 4

bookCreating Scatter Plots

Sveip for å vise menyen

Why Use Scatter Plots?

A scatter plot is ideal for:

  • Visualizing relationships between two numerical variables;

  • Detecting patterns, clusters, or outliers;

  • Exploring correlation (positive/negative/none).

Basic Syntax for Scatter Plots in ggplot2

ggplot(data = df, aes(x = variable_x, y = variable_y)) +
  geom_point()

To add group-based color, use: aes(x, y, color = group_var)

Example: Selling Price vs Kilometers Driven

ggplot(df, aes(x = km_driven, y = selling_price)) + 
  geom_point() + 
  labs(title = "Scatter Plot of Selling Price vs. Kilometers Driven",
       x = "Kilometers Driven", 
       y = "Selling Price")

This shows how a car’s usage relates to its price — often revealing depreciation trends.

question mark

Which ggplot2 function creates a scatter plot?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 5
some-alt