Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

D.

A LAB ASSIGNMENT-05
{NAME:RUDRASISH MISHRA} | {SECTION:IT-8} | {ROLL NO:1906649}

Q1). Explore any 5 built-in dataset and perform the following for each
dataset
● Display the summary
● Display the structure
● Display the first 5 rows
● Display the number of rows
● Display the number of columns
SOLUTION:

DS-1: UCBAdmissions:Student Admissions at UC Berkeley


INPUT:
data(UCBAdmissions)
summary(UCBAdmissions)
View(UCBAdmissions)
str(UCBAdmissions)
head(UCBAdmissions, 5)
nrow(UCBAdmissions)
ncol(UCBAdmissions)
OUTPUT:
DS-2: USArrests:Reasons for which criminals are arrested
in the US
INPUT:

data(USArrests)
summary(USArrests)
View(USArrests)
str(USArrests)
head(USArrests, 5)
nrow(USArrests)
ncol(USArrests)

OUTPUT:

DS-3: Titanic: Survival of passengers on the Titanic


INPUT:
data(Titanic)
summary(Titanic)
View(Titanic)
str(Titanic)
head(Titanic , 5)
nrow(Titanic)
ncol(Titanic)
OUTPUT:

DS-4: UKgas: UK Quarterly Gas Consumption


INPUT:
data(UKgas)
summary(UKgas)
View(UKgas)
str(UKgas)
head(UKgas , 5)
nrow(UKgas)
ncol(UKgas)
OUTPUT:

DS-5: USAccDeaths:Accidental Deaths in the US 1973-1978


INPUT:
data(USAccDeaths)
summary(USAccDeaths)
View(USAccDeaths)
str(USAccDeaths)
head(USAccDeaths , 5)
nrow(USAccDeaths)
ncol(USAccDeaths)
OUTPUT:

Q2). Explore any built-in dataset and plot the following


● Line Charts
● Bar Plot
● Histogram
● Pie Chart
● Dot Plots
● Box Plot
● Scatter Plot
● Kernel Density Plot
SOLUTION:

1.LINE CHARTS:
INPUT:
cars_649 <- c(1, 3, 6, 4, 9)
plot(cars_649)
plot(cars_649, type = "o")
plot(cars_649, type="o", col="blue")
plot(cars_649,type = "o", col = "black", xlab = "Month",
ylab = "Unit Produced")
trucks_649 <- c(1, 5, 7, 5, 5)
lines(trucks_649, type = "o", col = "blue")
OUTPUT:

2.DOT PLOTS:
INPUT:

month_649 <- month.name


expected_649 <- c(15, 16, 20, 31, 11, 6,
17, 22, 32, 12, 19, 20)
sold_649 <- c(8, 18, 12, 10, 41, 2,
19, 26, 14, 16, 9, 13)
quarter_649 <- c(rep(1, 3), rep(2, 3), rep(3, 3), rep(4, 3))
data_649 <- data.frame(month_649, expected_649, sold_649,
quarter_649)
dotchart(data_649$sold, labels = data_649$month, pch = 21,
bg = "green", pt.cex = 1.5)

OUTPUT:

3.BAR PLOT:

INPUT:

A_649 <- c(17, 2, 8, 13, 1, 22)


B_649 <- c("Jan", "feb", "Mar", "Apr", "May", "Jun")
barplot(A_649, names.arg = B_649, xlab ="Month",
ylab ="Articles", col ="green",
main ="MONTH VS ARTICLES")

OUTPUT:
4.BOX PLOT:
INPUT:

input_649 <- mtcars[,c('mpg','cyl')]


print(head(input_649))
boxplot(mpg ~ cyl, data = mtcars, xlab = "Number of
Cylinders",
ylab = "Miles Per Gallon", main = "Mileage Data")

OUTPUT:

5.HISTOGRAM:
INPUT:
input_649 <- table(Arthritis$Improved)
print(head(input_649))
barplot(input_649, main="Simple Bar Plot",
xlab="Improvement", ylab="Frequency")
OUTPUT:

6.PIE CHART:
INPUT:
city_649 <- c(23, 56, 20, 63)
label_649 <- c("FRANCE", "USA", "CHINA", "INDIA")
piepercent_649<- round(100 * city_649 / sum(city_649), 1)
pie(city_649, label_649 = piepercent_649,
main = "City pie chart", col = rainbow(length(city_649)))
legend("topright", c("FRANCE", "USA", "CHINA", "INDIA"),
cex = 0.5, fill = rainbow(length(city_649)))
OUTPUT:

7.SCATTER PLOT:
INPUT:
input_649 <- mtcars[, c('wt', 'mpg')]
plot(x_649 = input_649$wt, y_649 = input_649$mpg,
x_649lab = "Weight",
y_649lab = "Milage",
x_649lim = c(1.5, 4),
y_649lim = c(10, 25),
main = "Weight vs Milage"
)
OUTPUT:

8.KERNEL DENSITY PLOT:


INPUT:

den_649 = density(mtcars$mpg)
plot(den_649,main=" Kernel Density of Miles Per Gallon")
polygon(den_649, col="red", border="blue")

OUTPUT:

Q3).List and count the number of packages installed in the workspace


SOLUTION:
INPUT:
packinfo_649 <- installed.packages ()
print(packinfo_649)
cat("The number of packages installed in workspace
are:",nrow(packinfo_649))
ncol(packinfo_649)

OUTPUT:

Q4).Draw a Bubble Chart using ggplot2 package


SOLUTION:
INPUT:

library(ggplot2)
library(dplyr)
library(gapminder)
data_649 <- gapminder %>% filter(year=="2007") %>%
dplyr::select(-year)
ggplot(data_649, aes(x=gdpPercap, y=lifeExp, size = pop)) +
geom_point(alpha=0.7)

OUTPUT:

{NAME:RUDRASISH MISHRA} | {SECTION:IT-8} | {ROLL NO:1906649}

You might also like