Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 15

EXPERIMENT NO:04

Representation of the data using simple graph

EX:

#Create the data for the chart

A<-c(17,32,8,53,1)

barplot(A,xlab="x-axis",ylab="y-axis",main="Bar-chart")

OUTPUT

Creating a horizontal Bar chart

A<-c(17,32,8,53,1)

barplot(A,xlab="x-axis",ylab="y-axis",main="Bar-chart",horiz=T)

OUTPUT
#Creating data for the chart

A<-c(17,32,8,53,1,22)

B<-c("jan","feb","mar","apr","may","jun")

barplot(A,xlab="months",ylab="articles",main="article-chart",names.arg = B,col="black")

OUTPUT

Creating multi graph

EXAMPLE 1
A<-matrix(c(17,32,8,53,1,22,76,98,89,90,94,96,87,54,78),nrow=3,ncol=5,byrow=T)

B<-c("math","chem","phy","eng","social",)

barplot(A,xlab="subject",ylab="obtained numbers",main="Ramu result",names.arg =


B,col=c("black","red","green"),beside=T)

legend("topleft",subject,cex=1.5,fill=colors)

OUTPUT

EXAMPLE 2

A<-matrix(c(17,32,8,53,1,22,76,98,89,90,94,96,87,54,78),nrow=3,ncol=5,byrow=T)

B<-c("math","chem","phy","eng","social")

barplot(A,xlab="subject",ylab=" obtained numbers",main="Ramu result",names.arg =


B,col=c("black","red","green"))

legend("topleft",subject,cex=1.5,fill=colors)
EXAMPLE 3

A<-matrix(c(17,32,8,53,1,22,76,98,89,90,94,96,87,54,78),nrow=3,ncol=5,byrow=T)

B<-c("math","chem","phy","eng","social")

barplot(A,xlab="subject",ylab=" obtained numbers",main="Ramu result",names.arg =


B,col=c("black","red","green"),horiz=T)

legend("topleft",subject,cex=1.5,fill=colors)

EXAMPLE 4

A<-matrix(c(17,32,8,53,1,22,76,98,89,90,94,96,87,54,78),nrow=3,ncol=5,byrow=T)
B<-c("math","chem","phy","eng","social")

barplot(A,xlab="subject",ylab=" obtained numbers",main="Ramu result",names.arg =


B,col=c("black","red","green"),horiz=T,beside=T)

legend("topleft",subject,cex=1.5,fill=colors)

Creating pie-chart

A<-c(50,100,200,500)

B<-c("math","chem","phy","eng",)

pie(A,B)

OUTPUT
Pie chart including the title and colors

geeks<-c(100,150,200,250)

labels<-c("math","chem","phy","eng")

pie(geeks,labels,main="obtained marks",col=rainbow(length(geeks)))

OUTPUT

Slice percentage & chart legends

geeks<-c(100,150,200,250)
labels<-c("math","chem","phy","eng")

piepercent<-round(100*geeks/sum(geeks),1)

pie(greeks,labels,main="obtained marks",col=rainbow(length(greeks)))

legend("topright",c("math","chem","phy","eng"),cex=1.5,fill=rainbow(length(geeks)))

OUTPUT

Creating a simple Histogram

v<-c(32,45,65,47,55,57,54,66,67,68,71,72,73,74,89,85,86,83,82,91,98,95,97,93,96)

hist(v,xlab="No of articles",col="green",border="black")

OUTOUT
Ranges of X and Y valuesv<-c(19,23,11,5,16,21,32,14,19,27,39)

hist(v,xlab="No of articles",col="green",border="black",xlim=c(0,50),ylim=c(0,5),breaks=5)

OUTPUT

EXERCISE PROBLEM

1. Construct a bar chart for the following data: 234,345,321,543,346,465 and775

program

a<-c(234,345,321,543,346,456,775)
barplot(a,xlab="x-axis",ylab="y=axis",main="bar-char")

OUTPUT

2.Draw a bar chart along with titles and labels for the following data:

23,34,54,12,45 and 62

program

a<-c(23,34,54,12,45,62)

b<-c("math","chem","eng","eco","phy","social")

barplot(a,xlab="subjects",ylab="obtained number",main="Marks chart", names.arg=b)

OUTPUT
3. Draw a horizontal and vertical bar chart with titles,labels and colors for the following data:

112,134,135,165,189 and 192

program

a<-c(112,134,135,165,189,192)

b<-c("math","chem","eng","eco","phy","social")

barplot(a,xlab="subjects",ylab="obtained number",main="Marks chart", names.arg=b,col="blue")

OUTPUT

VERTICAL
HORIZONTAL

a<-c(112,134,135,165,189,192)

b<-c("math","chem","eng","eco","phy","social")

barplot(a,xlab="subjects",ylab="obtained number",main="Marks chart",


names.arg=b,col="blue",horiz=T)

OUTPUT

4. Create pie chart for the following data:


12,19,23,34 and 42

a<-c(12,19,23,34,42)

b<-c("Ramu","Sajjad","Dewans","Prajwal","Raj")

pie(a,b)

OUTPUT

5. Create a 3D pie chart with the following data:

23,35,34 and 53

program

library(plotrix)

slices<-c(23,35,34,53)

lbls<-c("A","B","C","D")

pie3D(slices,labels=lbls,explode=1.5,main="pie chart of countries")

OUTPUT
6. Following table shows the fequency distribution of college student according to their pocket money
(daily).Draw histogram and fequency polygon on the same graph paper.

program

midx<-seq(5,65,10);

frequency<-c(15,34,15,17,11,13,12);

x<-rep(midx,frequency);

brk<-seq(0,70,10);

hist(x,breaks=brk,main="college students",xlab="pocket money",ylab="No.of sudents");

OUTPUT
7.Create the histogram graph for the following data: 2,14,24,36,48,61,18 and 55

v<-c(2,14,24,36,48,61,18,55)

hist(v,xlab="No.of article",col="gray",border="white")

OUTPUT

You might also like