2023년 1월 21일 토요일

more examples of creating a basic scatter plot in R using different data and options:

Here are a few more examples of creating a basic scatter plot in R using different data and options:

  1. Using the scatterplot() function from the car package to create a scatter plot with a fitted line and a confidence interval:
 Load the car package 
library(car) 
# Create scatter plot with a fitted line and a confidence interval 
scatterplot(x = mtcars$wt, y = mtcars$mpg, xlab = "Weight", ylab = "Miles per Gallon", main = "Scatter Plot of Weight vs Miles per Gallon", smooth = TRUE, reg.line = lm, ci = TRUE)
  1. Using the ggplot2 package to create a scatter plot with different shapes and colors for each group of data:
# Load the ggplot2 package 
library(ggplot2) 
 # Create scatter plot with different shapes and colors for each group of data 
ggplot(mtcars, aes(x = wt, y = mpg, shape = factor(cyl), color = factor(cyl))) + geom_point() + xlab("Weight") + ylab("Miles per Gallon") + ggtitle("Scatter Plot of Weight vs Miles per Gallon by Number of Cylinders")
  1. Using the scatterplotMatrix() function from the car package to create a matrix of scatter plots:
# Load the car package 
library(car) 
# Create a matrix of scatter plots 
scatterplotMatrix(~wt + mpg + hp + drat + qsec, data = mtcars, xlabels = TRUE, ylabels = TRUE, main = "Scatter Plot Matrix of Car Attributes")

More

댓글 없음:

댓글 쓰기