Write a R program to create a simple bar plot of five subjects marks

1. Introduction

This R program creates a simple bar plot for the marks of five subjects. It visualizes the marks for each subject in a bar chart format.

2. Program Steps

1. Define the marks for five subjects.

2. Define the names of the five subjects.

3. Create a bar plot using the subject names and their corresponding marks.

4. Display the bar plot.

3. Code Program

# Define the marks for five subjects
marks <- c(80, 70, 90, 85, 75)

# Define the names of the subjects
subjects <- c("Maths", "Science", "English", "History", "Geography")

# Create a bar plot
barplot(marks, names.arg = subjects, col = "blue", main = "Marks in Five Subjects", xlab = "Subjects", ylab = "Marks")

Output:

[A bar plot displaying marks in five subjects with subjects on the x-axis and marks on the y-axis]

Explanation:

1. c(80, 70, 90, 85, 75): Defines a vector of marks for the subjects.

2. c("Maths", "Science", "English", "History", "Geography"): Defines a vector of subject names.

3. barplot(marks, names.arg = subjects, col = "blue", main = "Marks in Five Subjects", xlab = "Subjects", ylab = "Marks"): Creates a bar plot with the defined marks and subjects. The plot is colored blue and includes labels and a title.


Comments