set.seed(123)
x <- rnorm(100)
y <- rnorm(100, mean = 1)
# Plotting using plot()
plot(x, y, main = "Scatterplot", xlab = "X", ylab =
"Y")
# Histogram using hist()
hist(x, main = "Histogram", xlab = "Value", col =
"skyblue")
# Line chart using plot()
time <- 1:100
values <- sin(time/10) + rnorm(100, sd = 0.2)
plot(time, values, type = "l", main = "Line Chart",
xlab = "Time", ylab = "Value")
# Pie chart using pie()
categories <- c("A", "B", "C", "D")
sizes <- c(20, 30, 10, 40)
pie(sizes, labels = categories, main = "Pie Chart")
# Boxplot using boxplot()
boxplot(x, y, main = "Boxplot", names = c("X", "Y"),
col = c("skyblue", "lightgreen"))
# Scatterplot using plot()
plot(x, y, main = "Scatterplot", xlab = "X", ylab =
"Y")
# Adding a regression line to the scatterplot
abline(lm(y ~ x), col = "red")
0 Comments