Next →

Output:


      

Plots:

Scatter Plots

Scatter plots are used to visualize the relationship between two numeric variables. In R, you can use the base plot() function or ggplot2 for more advanced plotting.

Basic Scatter Plot

# Sample data
x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 1, 5, 3)

# Create a scatter plot
plot(x, y, main = "Basic Scatter Plot", xlab = "X Values", ylab = "Y Values", col = "blue", pch = 19)

Using ggplot2

library(ggplot2)

df <- data.frame(x = x, y = y)

ggplot(df, aes(x = x, y = y)) +
  geom_point(color = "red", size = 3) +
  ggtitle("Scatter Plot with ggplot2") +
  theme_minimal()

Scatter plots help identify correlations, trends, and outliers in your data.