Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

10. Write a R program for any visual representation of an object with creating graphs using graphic functions: Plot(),Hist(),Linechart(),Pie(),Boxplot(),Scatterplots().

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") 

Post a Comment

0 Comments