Professional Documents
Culture Documents
A LAB ASSIGNMENT-5
NAME : RICHA GUPTA
ROLL NO : 1906569
SECTION : IT-7
#1.
1. Explore any 5 built-in dataset and perform the following for each dataset
INPUT:
data(PlantGrowth )
str(PlantGrowth )
head(PlantGrowth,5)
nrow(PlantGrowth )
ncol(PlantGrowth )
data(ToothGrowth)
str(ToothGrowth)
head(ToothGrowth,5)
nrow(ToothGrowth)
ncol(ToothGrowth)
data(EuStockMarkets)
str(EuStockMarkets)
head(EuStockMarkets,5)
nrow(EuStockMarkets)
ncol(EuStockMarkets)
data(HairEyeColor )
str(HairEyeColor)
head(HairEyeColor,5)
nrow(HairEyeColor )
ncol(HairEyeColor )
data(Nile)
str(Nile)
head(Nile,5)
nrow(Nile)
ncol(Nile)
OUTPUT :
#2. 2. Explore any built-in dataset and plot the following
Line Charts
Bar Plot
Histogram
Pie Chart
Box Plot
Scatter Plot
Kernel Density Plot
SOLUTION:
INPUT:
LINE CHARTS
cars <- c(1, 2, 3, 4, 5)
plot(cars)
plot(cars, type = "o")
plot(cars, type="o", col="blue")
OUTPUT:
BAR PLOT
INPUT:
H <- c(7,12,28,3,41)
barplot(H)
M <- c("Mar","Apr","May","Jun","Jul")
barplot(H,names.arg=M,xlab="Month",ylab="Revenue",col="blue",
OUTPUT:
INPUT
colors = c("green","orange","brown")
months <- c("Mar","Apr","May","Jun","Jul")
regions <- c("East","West","North")
values <- matrix(c(2,9,3,11,9,4,8,7,3,12,5,2,8,10,11), nrow = 3, ncol = 5, byrow = TRUE)
barplot(values, main = "Total Revenue", names.arg = months, xlab = "month", ylab
OUTPUT:
Histogram
INPUT :
v <- c(9,13,21,8,36,22,12,41,31,33,19)
hist(v,xlab = "Weight",col = "yellow",border = "blue")
hist(v,xlab = "Weight",col = "blue",border = "red", xlim = c(0,40), ylim = c(0,5),breaks=5)
OUTPUT:
PIE CHART
INPUT:
x <- c(21, 62, 10, 53)
labels <- c("London", "New York", "Singapore", "Mumbai")
pie(x,labels)
pie(x, labels, main = "City pie chart", col = rainbow(length(x)))
piepercent<- round(100*x/sum(x), 1)
pie(x, labels = piepercent, main = "City pie chart",col = rainbow(length(x)))
legend("topright", c("London","New York","Singapore","Mumbai"), cex = 0.8,fill=rainbow(length(x))
OUTPUT
INPUT :
install.packages("plotrix")
library(plotrix)
x <- c(21, 62, 10,53)
lbl <- c("London","New York","Singapore","Mumbai")
pie3D(x,labels = lbl, explode = 0.1, main = "Pie Chart of Countries") #2.4.Dot Chart
dotchart(PlantGrowth$weight,col="red",pch=1,labels=PlantGrowth$group, main="group vs
weight", xlab="weight")
pg <- PlantGrowth
pg$color[pg$group=="ctrl"] <- "red"
pg$color[pg$group=="trt1"] <- "Violet"
pg$color[pg$group=="trt2"] <- "blue“
dotchart(PlantGrowth$weight, labels=PlantGrowth$group,cex=0.8,groups= PlantGrowth$group,
main="group vs weight",xlab="weight",gcolor="black",color=pg$color)
OUTPUT:
INPUT:
data2 = USArrests[order(USArrests$Murder),]
dotchart(data2$Murder, labels = row.names(data2),
cex = .5, main = "Murder arrests by state, 1973",
xlab = "Murder arrests per 100,000 population")
OUTPUT
BOX PLOT
INPUT:
OUTPUT:
Scatter Plot:
INPUT:
input <- mtcars[,c('wt','mpg')]
plot(x = input$wt,y = input$mpg,
xlab = "Weight",
ylab = "Age",
xlim = c(2.5,5),
ylim = c(15,30),
main = "Weight vs Age"
)
OUTPUT:
Scatter Plot
INPUT
input <- mtcars[,c('wt','mpg')]
plot(x = input$wt,y = input$mpg,
xlab = "Weight",
ylab = "Age",
xlim = c(2.5,5),
ylim = c(15,30),
main = "Weight vs Age"
)
OUTPUT
INPUT:
den = density(mtcars$mpg)
plot(den,main=" Kernel Density of Miles Per Gallon") polygon(d, col="red",
border="blue")
OUTPUT:
INPUT:
OUTPUT: