Basic Scatter Plot with plot() in R

Learn how to create a basic scatter plot in R using the base plot() function with random data, titles, and color customization for beginners.

Brief Introduction

Basic Scatter Plot with plot() in R (r)
DESCRIPTION:
Simple and complete example to create a scatter plot using the base plot() function in R. The code generates random data, visualizes it, and customizes the plot with titles and colors.

ADDITIONAL NOTES:
This example is ideal for beginners working with plots in R who want to understand how to use the plot() function to visualize numerical data. It does not require external packages and can be run in any standard R environment.

EXPLANATIONS:
- set.seed(123): sets the seed for random generation so results are reproducible.
- x <- rnorm(50): generates 50 random numbers with standard normal distribution for the x-axis.
- y <- rnorm(50): generates 50 random numbers with standard normal distribution for the y-axis.
- plot(x, y, ...): creates the scatter plot with x and y data, customizing the title, axis labels, and point color.

Example Code: r

# Set the seed for reproducibility of random data
set.seed(123)

# Generate 50 random points for the x-axis with normal distribution
x <- rnorm(50)

# Generate 50 random points for the y-axis with normal distribution
y <- rnorm(50)

# Create a basic scatter plot with plot()
plot(x, y,
     main = "Basic Scatter Plot with plot()",
     xlab = "X Axis",
     ylab = "Y Axis",
     col = "blue",      # Color of the points
     pch = 19)           # Point type: solid circle
×
×
×
Do you want to regenerate the answer?
×
Export chat
Choose export format
Generazione PDF in corso…
Allegati
×
You are about to close the chat and switch to the image generator. If you are not logged in, you will lose our chat. Do you confirm?
You are viewing a shared chat in temporary mode. It will not be saved.
×
Saved prompts
×
Private note
×
Label
×
Search all chats
×
Your insights
Analyzing…
×
AI Preferences
Assistant name 30
Answer length
AI model
Structured answers
Include examples
Use emojis
Guide me, don't solve Hints and questions instead of a ready answer
More settings →
×
Share this chat
Anyone opening this link can view the chat or add it to their profile as their own chat.
Note: the chat attachments will be shared too. Anyone who adds it will receive a copy of the files in their own folder.
Shared chat
Someone shared a chat with you. Do you want to just view it or add it to your chats?
Note: the chat attachments will be shared too. Anyone who adds it will receive a copy of the files in their own folder.
×

Saved messages

Loading...

×

Chat History

example-programs · CHAT HISTORY

Loading...

AI Preferences

×
  • BasicQuick and essential answers for study
  • MediumHigher quality for study and programming
  • AdvancedComplex reasoning and detailed analysis
Explain Steps

What do you need?

R base: no external library required

plot() function: base R function to create plots

set.seed(): for reproducibility of random data

Data generated with rnorm(): generation of random numbers with normal distribution

Plot configuration: titles, axis labels, point color

Plot output: visualization in R graphical window (RStudio or R GUI)

Similar Topics