Graphical representation of data. Experiment :1 Bar Graph Experiment :2 Pie Graph Experiment :3 Histograms Experiment :4 Boxplot
df=data.frame(Name=c("John","Bill","Maria","Tom","Emma"),age=c(23,41,32,55,40))
df
write.csv(df,"people.csv",row.names=FALSE)
#Built-in Data
data(mtcars)
head(mtcars,6)
#BAR Graph
x=c("Punjab","Harayana","U.P","Gujarat","Bihar","Karnataka")
y=c(728,943,1469,2903,2153,2276)
barplot(y,names.arg=x,col="red",main="Yield of rice in Kg. Per Acre in various states of india",xlab="States",ylab="Yield")
#Multiple Bar Graph
clg=c("A","B","C","D")
clgA=c(120,260,500)
clgB=c(100,180,650)
clgC=c(140,300,850)
clgD=c(750,900,300)
d=data.frame(clgA,clgB,clgC,clgD)
d1=as.matrix(d)
barplot(d1,beside=T,names.arg=clg,xlab="College",ylab="No.Of Students",col=c("orange","white","green"),border="black")
legend("topleft",legend=c("ARTS","SCIENCE","COMMERSE"),fill=c("orange","white","green"),border="black")
#subdivided_VERTICAL
barplot(d1, beside = F, names.arg = clg, xlab = "College", ylab = "No. of students",col = c("Green","red","yellow"))
legend("topleft",legend = c("ARTS","SCIENCE","COMMERSE"), fill =c("green","red","yellow"),border = "black")
#SUBDIVIDED HORIZONTAL
barplot(d1, beside = F, horiz = T, names.arg = clg, xlab = "College", ylab = "No. of students",col = c("Green","red","yellow"))
legend("bottomright",inset = c(0, -0.01),legend =c("ARTS","SCIENCE","COMMERSE"), fill=c("green","red","yellow"),border = "black",cex = 0.4)
#PIE_CHART
item =c('Food','Clothing','Recreation','Electric','Movie','Rent')
exp = c(87, 24, 11, 13, 25, 20)
pie(exp, main='Expenditure', labels = item, radius =1, col = rainbow(length(exp)))
#PIE SLICE PER%
x =c(21,62,10,53)
labels= c("London","NewYork","Singapore","Mumbai")
piepercent= round(100*x/sum(x),1)
png(file ="city_percentage_legends.jpg")
pie(x, labels =piepercent, main ="City pie chart",col= rainbow(length(x)))
legend("topright", c("London","NewYork", "Singapore","Mumbai"), cex=0.8,
fill= rainbow(length(x)))
dev.off()
#HISTOGRAM
x=seq(150,175,5)
f=c(6,11,14,9,3,2)
y=rep(x,f)
t=seq(147.5,177.5,5)
hist(y,breaks=t,col=1:6)
#PIE_CHART
item =c('Food','Clothing','Recreation','Electric','Movie','Rent')
exp = c(87, 24, 11, 13, 25, 20)
pie(exp, main='Expenditure', labels = item, radius =1, col = rainbow(length(exp)))
#PIE SLICE PER%
x =c(21,62,10,53)
labels= c("London","NewYork","Singapore","Mumbai")
piepercent= round(100*x/sum(x),1)
png(file ="city_percentage_legends2.jpg")
pie(x, labels =piepercent, main ="City pie chart",col= rainbow(length(x)))
legend("topright", c("London","NewYork", "Singapore","Mumbai"), cex=0.8,
fill= rainbow(length(x)))
dev.off()
#HISTOGRAM Ungrouped
x=seq(150,175,5)
f=c(6,11,14,9,3,2)
y=rep(x,f)
t=seq(147.5,177.5,5)
hist(y,breaks=t,col=1:6)
#HISTOGRAM Grouped Data
midx=seq(12.5,112.5,25)
f=c(5,8,13,11,3)
climit=seq(0,125,25)
y=rep(midx,f)
hist(y,breaks=climit,col=6:1)
#Box Plot
input=mtcars[,c('mpg','cyl')]
print(head(input))
boxplot(mpg ~cyl,data=mtcars,xlab = "Number Of Cylinders",
ylab="Miles Per Gallon",main="Mileage Data",col=c("red","green","yellow"))
#Box Plot
data("iris")
iris
boxplot(Sepal.Length~Sepal.Width,data=iris,xlab="Sepal Width",
ylab="Sepal Length",main="Iris data",col=c("red","green","yellow"))
Comments
Post a Comment