Write an R script to create a scatter plot, incorporating categorical analysis through color-coded data points representing different groups, using ggplot2.
Step 1: Load necessary libraries
# Load necessary librarieslibrary(ggplot2)
Warning: package 'ggplot2' was built under R version 4.1.3
library(dplyr)
Warning: package 'dplyr' was built under R version 4.1.3
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
Step 2: Load the Dataset
Explanation:
The iris dataset contains 150 samples of iris flowers categorized into three species: setosa, versicolor, and virginica.
Each sample has sepal and petal measurements.
head(data) displays the first few rows.
# Load the iris datasetdata <- iris# Display first few rowshead(data)