0% found this document useful (0 votes)
22 views9 pages

Muthayammal College of Arts and Science Rasipuram: Assignment No - 2

The document is an assignment submission for a course on R Programming for Data Analysis. It includes examples of creating bar diagrams, histograms, ogive curves, and frequency polygons in R. For each graph type, it provides the required syntax, sample code to generate the graph, and an image of the output graph.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views9 pages

Muthayammal College of Arts and Science Rasipuram: Assignment No - 2

The document is an assignment submission for a course on R Programming for Data Analysis. It includes examples of creating bar diagrams, histograms, ogive curves, and frequency polygons in R. For each graph type, it provides the required syntax, sample code to generate the graph, and an image of the output graph.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Muthayammal College of Arts And Science

Rasipuram
Assignment No - 2

Name : K.Haritha

Roll no : 21UST004

Department : III- B.Sc., Statistics

Subject : R Programming For Data Analysis

Date :

K.Haritha

Student Signature Staff Signature


R PROGRAMMING FOR DATA ANALYSIS
UNIT -2

1.BAR DIAGRAM

In R, a bar chart is a graphical representation of categorical data using rectangular bars.


Each bar's length is proportional to the value it represents. Bar charts are often used to display
and compare the frequency, count, or other summary measures for different categories or
groups.

Syntax

barplot(H, xlab, ylab, main, names.arg, col)

H: This parameter is a vector or matrix containing numeric values which are used in bar
chart.

xlab: This parameter is the label for x axis in bar chart.

ylab: This parameter is the label for y axis in bar chart.

main: This parameter is the title of the bar chart.

names.arg: This parameter is a vector of names appearing under each bar in bar chart.

col: This parameter is used to give colors to the bars in the graph.

PROGRAM

c1<-1995:2000;

c2<-c(15,25,27,28,26,26.6);

sales.year<-data.frame(year=c1,sales=c2);

sales.year;

attach(sales.year);

barplot(sales,xlab="year",ylab="sales",main="",col="white");
OUTPUT

BAR DIAGRAM IN R
2.HISTOGRAM

A histogram contains a rectangular area to display the statistical information which is


proportional to the frequency of a variable and its width in successive numerical intervals. A
graphical representation that manages a group of data points into different specified ranges. It
has a special feature that shows no gaps between the bars and is similar to a vertical bar
graph.

We can create histograms in R Programming Language using the hist() function

Syntax: hist(v, main, xlab, xlim, ylim, breaks, col, border)

v: This parameter contains numerical values used in histogram.

main: This parameter main is the title of the chart.

col: This parameter is used to set color of the bars.

xlab: This parameter is the label for horizontal axis.

border: This parameter is used to set border color of each bar.

xlim: This parameter is used for plotting values of x-axis.

ylim: This parameter is used for plotting values of y-axis.

breaks: This parameter is used as width of each bar.

PROGRAM

# Create a histogram

hist(data,

main="Histogram Example", # Main title

xlab="Values", # X-axis label

ylab="Frequency", # Y-axis label

col="blue", # Color of bars

border="black", # Color of bar borders


breaks=5) # Number of bins

OUTPUT

HISTOGRAM IN R
3.OGIVE CURVE

An ogive in statistics is a line graph that represents the cumulative distribution of a


dataset. It shows the cumulative frequency or cumulative relative frequency of data points in
a dataset, presenting a visual representation of the distribution of values. The cumsum()
function is used to calculate the cumulative sum of the frequencies, and then the plot()
function is used to create the ogive. The argument type = "o" specifies that points should be
connected by lines, and col and lwd are used to set the color and line width.

PROGRAM

# Sample data

data <- c(10, 15, 20, 25, 30, 35, 40, 45, 50)

data <- sort(data) # Sort the data in ascending order

# Calculate cumulative frequencies

cum_freq <- cumsum(table(data))

# Create the ogive plot

plot(unique(data), cum_freq,

type = "o", # "o" for overplotted points and lines

lwd = 2, # Line width

col = "blue", # Line color

xlab = "Values", # X-axis label

ylab = "Cumulative Frequency", # Y-axis label

main = "Ogive Example") # Main title


OUTPUT

OGIVE IN R
4.FREQUENCY POLYGON

A frequency polygon in R is a graphical representation of a dataset that displays the


distribution of values. It is similar to a line graph, with points representing the frequencies of
different values and lines connecting these points. The frequency polygon is particularly
useful for displaying the shape of a distribution and identifying patterns or trends in the data.
The plot() function is used to create the frequency polygon. The argument type = "o"
specifies that points should be connected by lines, and col and lwd are used to set the color
and line width.Frequency polygons are beneficial for visualizing the distribution of data,
revealing patterns, and comparing datasets.

PROGRAM

# Generate some sample data

data <- c(23, 25, 30, 32, 35, 38, 40, 42, 45, 50, 55, 60)

# Create a histogram

hist_data <- hist(data,

plot = FALSE, # Set to FALSE to prevent plotting the histogram

breaks = 5) # Number of bins (adjust as needed)

# Create a frequency polygon

plot(hist_data$mids, hist_data$counts,

type = "o", # "o" for overplotted points and lines

lwd = 2, # Line width

col = "blue", # Line color

xlab = "Values", # X-axis label

ylab = "Frequency", # Y-axis label

main = "Frequency Polygon Example") # Main title


OUTPUT

FREQUENCY POLYGON IN R

You might also like