1. Introduction
This R program demonstrates how to represent data graphically using R's built-in functions. For illustration, we'll use a simple dataset and create different types of graphs such as bar plots, histograms, and line plots.
2. Program Steps
1. Create a dataset.
2. Generate a bar plot.
3. Generate a histogram.
4. Generate a line plot.
5. Display all plots.
3. Code Program
# Step 1: Create a dataset
data <- c(2, 5, 3, 9, 8, 11, 6)
# Step 2: Generate a bar plot
barplot(data, main = "Bar Plot", xlab = "Index", ylab = "Value")
# Step 3: Generate a histogram
hist(data, main = "Histogram", xlab = "Value", ylab = "Frequency")
# Step 4: Generate a line plot
plot(data, type = "o", col = "blue", main = "Line Plot", xlab = "Index", ylab = "Value")
# Note: Each of these plotting commands will generate a separate window with the plot.
Output:
[Bar Plot, Histogram, and Line Plot generated in separate windows]
Explanation:
1. data <- c(2, 5, 3, 9, 8, 11, 6): Creates a simple dataset for the demonstration.
2. barplot(data, main = "Bar Plot", xlab = "Index", ylab = "Value"): Generates a bar plot of the data.
3. hist(data, main = "Histogram", xlab = "Value", ylab = "Frequency"): Creates a histogram to show the frequency distribution of the data.
4. plot(data, type = "o", col = "blue", main = "Line Plot", xlab = "Index", ylab = "Value"): Generates a line plot of the data.
5. Each plot command creates a separate graph window displaying the respective plot type.
Comments
Post a Comment