B.Sc Computer Science
R Programming - Lab
Bharathiar University
Program 7
Graphs in R
Program 6- Write a R program to demonstrate various types of graphs
SOURCE CODE:
# Create sample data
x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 6, 8, 10)
par(mfrow = c(2, 2))
# Plot a basic line graph
pts <- c(2,3,4,6,8)
plot(pts, type = "o", col = "blue", lwd = 2, main = "Simple Line Graph", xlab = "X-axis", ylab = "Y-axis")
# Add points to the graph
points(pts, col = "red", pch = 16)
barplot(c(3, 5, 2, 7, 4), names.arg = c("A", "B", "C", "D", "E"), col = "orange", main = "Bar Plot", xlab = "Categories", ylab = "Values")
plot(x, y, col = "green", pch = 18, main = "Scatter Plot", xlab = "X-axis", ylab = "Y-axis")
boxplot(x, col = "blue", names = "X", main = "Box Plot", xlab = "Variables", ylab = "Values")