0% found this document useful (0 votes)
47 views12 pages

B4 Notes

This document contains 10 questions and R code snippets related to creating different types of plots and charts in R. It asks the reader to plot points, histograms, scatter plots, lines, bar charts and pie charts using built-in R functions like plot(), hist(), barplot() and pie(). For each question, it provides the necessary R code to generate the specified plot or chart and modify features like colors, labels, legends. The questions cover a range of basic to intermediate plotting skills in R.

Uploaded by

yash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views12 pages

B4 Notes

This document contains 10 questions and R code snippets related to creating different types of plots and charts in R. It asks the reader to plot points, histograms, scatter plots, lines, bar charts and pie charts using built-in R functions like plot(), hist(), barplot() and pie(). For each question, it provides the necessary R code to generate the specified plot or chart and modify features like colors, labels, legends. The questions cover a range of basic to intermediate plotting skills in R.

Uploaded by

yash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

0801IT211098

YASH RUGHWANI
ASSIGNMENT-6
Q.1 Plot Miles/(US) gallon versus Rear axle ratio by plot(mpg,drat). On which
axis does mpg appear?
a. mpg appears on the x axis
b. mpg appears on the y axis
Q.2Produce a histogram with hist(gear). What do you see?
a. frequencies
b. probability density

> print("IT98 yash rughwani")


[1] "IT98 yash rughwani"
> attach(mtcars)
> hist(gear)
Q3 Change type of visualization of our scatterplot in Exercise 1
plot(mpg,drat,type=””). If we want to see lines what we have to type into “
”: a.type=”l” b.type=”p”

> print("IT98 yash rughwani")


[1] "IT98 yash rughwani"
attach(mtcars)
plot(mpg,drat,type="l")
Q.4 Take a two vector and plot points .(take atleast 5 number in each)

vector1 <- c(1, 3, 5, 7, 9)


vector2 <- c(2, 4, 6, 8, 10)
plot(vector1, vector2)
Q5 Draw a line of sequence 10 to 100.and change line color blue,red,green.

x <- seq(10, 100)


plot(x, type = "l")
lines(x, col = "blue")
lines(x, col = "red")
lines(x, col = "green")
Q6 Write a R program to create a simple bar plot of five subjects marks.

marks <- c(80, 75, 90, 85, 70)


barplot(marks, names.arg = c("Subject 1", "Subject 2", "Subject 3", "Subject 4",
"Subject 5"))
title("Subject Marks")
xlabel=("Subjects")
ylabel=("Marks")
Q7 Draw a scatter plot of two vector of unequal length. And also provide label
on horizontal and vertical axis.

x <- c(1, 2, 3, 4, 5)
y <- c(10, 20, 15)
plot(x, y, main = "Scatter Plot of Two Vectors", xlab = "Vector X", ylab = "Vector
Y")
legend("topright", legend = "Data Points", pch = 1)
Q8 1.Draw a pie chart for 5 vector value.
2. set start angle for pie chart
3.label 4.main 5.legend
>x<-c(10,20,30,40,50)
> pie(x)
2.
> pie(x,init.angle=90)
3+4.

> x<-c(10,20,30,40,50)
> mylabel<-c("APPLES","BANANAS","MANGO","ORANGE","GRAPES")
> pie(x,label=mylabel,main="FRUITS")
5.

>mylabel<-c("APPLES","GRAPES","MANGOES","WATERMELON","CHERRY
")
> colors<-c("RED","PURPLE","YELLOW","GREEN","PINK")
> pie(x,label=mylabel,main="Pie Chart",col=colors)
> legend("bottomleft",mylabel,fill=colors)
Ques9)Draw a bar chart for student name
and marks. 1 Set bar color green and red.
2.set density and width(1
or 2 or 3) Program:
> marks<-c(17,32,66,40,23,34,64,61,47,54)

>studentname<-c("AAYUSH","NITESH","YASHR","YASHV","UMANG","PRA
NAY","KAUSH AL","KISHAN","MANYA","DIVYA")

>barplot(marks,names.arg=studentname,xlab="MARKS",ylab="STUDENTNAM
ES",col="green", main="CLASS ANALYSIS")
>barplot(marks,names.arg=studentname,xlab="MARKS",ylab="STUDENTNAM
ES",col="RED",
main="CLASS ANALYSIS")

>barplot(marks,names.arg=studentname,xlab="MARKS",ylab="STUDENTNAM
ES",col="RED", main="CLASS ANALYSIS",width=c(1,3,2,2,1,2,3,1,3,2))
Ques10)Draw horizontal bar student name and marks
(10 students). Program:

> x<-c(17,32,89,40,23)

> marks<-c(17,32,66,40,23,34,64,61,47,54)

>studentname<-c("AAYUSH","NITESH","YASHR","YASHV","UMANG","PRA
NAY","KAUS HAL","KISHAN","MANYA","DIVYA")

>barplot(marks,name.arg=studentname,horiz=TRUE,xlab="marks",ylab="studentn
ame",main=" Horizontal Bar-Chart”)

You might also like