0% found this document useful (0 votes)
21 views59 pages

FDS Lab Record

Uploaded by

vishvakarthik06
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)
21 views59 pages

FDS Lab Record

Uploaded by

vishvakarthik06
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/ 59

WORKING OF BASIC NUMPY PROGRAMS

Ex.NO. : 1(a) Sorting The Array Elements in Ascending Order


Date :

AIM :

To write a python program to sort the list of items in ascending order.

ALGORITHM :

1.Start the program


2. Declare array elements into an variable
3. Use sort()
4. Print the result
5. End the program

PROGRAM :

arr=[7,3,1,2,5]
arr.sort()
print(arr)

OUTPUT:

[1, 2, 3, 5, 7]

RESULT:
Thus the program was executed successfully and the output is verified.
Ex.No. : 1(b) Sorting The Array elements in Descending Order
Date :

AIM :

To write a python program to sort the list of items in descending order.

ALGORITHM :

1.Start the program


2. Declare array elements into an variable
3. Use sort(reverse==True)
4. Print the result
5. End the program

PROGRAM:

arr=[7,3,1,2,5]
arr.sort(reverse=true)
print(arr)

OUTPUT:

[7, 5, 3, 2, 1]

RESULT:

Thus the program was executed successfully and the output is verified.
Ex.No. : 1(c) Addition and Subtraction Operations in matrix using Numpy
arrays
Date :

AIM :

To write a python program to perform matrix operations using numpy


arrays.

ALGORITHM :

1. Start the program


2. Import numpy library
3. Declare array elements into two variables
4. To add() and sub() functions, pass the array variables
5. Print the result
6. End the program

PROGRAM :

import numpy as np
a=np.array([1,2],[2,1])
b=np.array([3,4],[4,3])
r1=np.add(a,b)
r2=np.sub(a,b)
print(r1)
print(r2)

OUTPUT:

[[4 6]
[6 4]]

[[-2 -2]
[2 2]]
RESULT:

Thus the program is executed successfully and the output is verified


Ex. No. :1(d) Matrix multiplication
Date :

AIM:

To write a python program to perform matrix multiplication using numpy


arrays

ALGORITHM:

1. Start the program


2. Import numpy library
3. Declare array elements into two arrays
4. To matmul() function, pass the two variables
5. Print the resultant array
6. End the program

PROGRAM:

import numpy as np
a=[[2,4],[6,8]]
b=[[1,3],[5,7]]
print(np.matmul(a,b))

OUTPUT:

[[22 34]
[46 74]]

RESULT:

Thus the program is executed successfully and the output is verified


Ex. No. : 02(a) Transpose of matrix

Date:

AIM:

To write a python program to find transpose of a matrix using numpy arrays

ALGORITHM:

1. Start the program


2. Import numpy library
3. Declare array elements to a variable
4. Store the transpose of the array in another variable using transpose()
5. Print the resultant array
6. End the program

PROGRAM:

import numpy as np

a=np.array([1,2],[3,4])

b=a.transpose()

print(b)

OUTPUT:

[[1 3]

[2 4]]
RESULT:

Thus the program is executed successfully and the output is verified


Ex. No. :02(b) Conversion of one dimensional array to 2 dimensional array

Date :

AIM:

To write a python program to convert an one dimensional array into a two


dimensional array using numpy.

ALGORITHM:

1. Start the program


2. Import numpy library
3. Declare array elements to a variable
4. In a new variable using reshape() convert into a 2D array with desired
parameters
5. Print the resultant array
6. End the program

PROGRAM:

import numpy as np

arr=np.array([1,3,5,7,9,11,13,15])

b=np.reshape(4,2)

print(b)

OUTPUT:

[[1 3]

[5 7]

[9 11]
[13 15]]

RESULT:

Thus the program is executed successfully and the output is verified


Ex. No. :02(c) Conversion of binary numpy array to boolean numpy array

Date:

AIM:

To write a python program to convert a binary numpy array into a boolean


numpy array

ALGORITHM:

1. Start the program


2. Import numpy library
3. Declare array elements for a variable in binary format
4. Using astype function and bool as parameter, convert the array to boolean
array
5. Print the resultant array
6. End the program

PROGRAM:

import numpy as np

a=np.array([1,0,1,1,0])

b=astype(bool)

print(b)

OUTPUT:

[True False True True False]


RESULT:

Thus the program is executed successfully and the output is verified


Ex. No. : 02(d) Conversion of one datatype to another

Date:

AIM:

To write a python program to convert an array of one datatype into another


datatype using numpy

ALGORITHM:

1. Start the program


2. Import numpy library
3. Declare array elements to a variable
4. Using astype function, convert the array to any datatype by passing the
type into the function as parameter
5. Print the resultant array
6. End the program

PROGRAM:

import numpy as np

a=np.array([1.4, 7.4, 6.0, 2.1])

b=a.astype(int)

print(b)
OUTPUT:

[1 7 6 2]

RESULT:

Thus the program is executed successfully and the output is verified


Ex. No. :03(a) Horizontal stack and Vertical stack for numpy array

Date:

AIM:

To write a python program to perform horizontal stack and vertical stack of


numpy array

ALGORITHM:

1. Start the program


2. Import numpy library
3. Declare array elements to a variable
4. Using hstack perform stacking to the variable and print the result
5. End the program

PROGRAM:

import numpy as np

a=np.array([10,20,30])

b=np.hstack(a)

c=np.vstack(a)

print(“Horizontal stack”)

print(b)

print(“Vertical stack”)

print(c)

OUTPUT:

Horizontal stack
[10 20 30]

Vertical stack

[[10]

[20]

[30]]

RESULT:

Thus the program is executed successfully and the output is verified


Ex. No. :3(b) Generating sequence of numbers
Date:

AIM:

To write a numpy program to generate a sequence of numbers from 0 to 50


with intervals of 2 numbers

ALGORITHM:

1. Start the program


2. Import numpy library
3. Using arange pass the start value, end value and interval value and store
the resultant to a variable
4. Print the array
5. End the program

PROGRAM:

import numpy as np
a=np.arange(0,50,2)
print(a)

OUTPUT:

[0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48]

RESULT:

Thus the program is executed successfully and the output is verified


Ex. No. : 3(c) Getting position of numpy array
Date:

AIM:

To write a numpy program to get the position where the elements of two
numpy arrays match

ALGORITHM:

1. Start the program


2. Import numpy library
3. Declare two array variables and assign them values
4. Print the position by using where() by passing the two variables are equal
as condition
5. End the program

PROGRAM:

import numpy as np
a=np.array([2,3,5,5])
b=np.array([2,4,5,6])
print(np.where(a==b))

OUTPUT:

array([0,2],dtype=int64)

RESULT:

Thus the program is executed successfully and the output is verified


Ex. No. :03(d) Count of equally spaced numbers within specific range
Date:

AIM:

To write a numpy program to count equally spaced number within a


specific range

ALGORITHM:

1. Start the program


2. Import numpy library
3. Using count_nonzero() function, find the numbers that are equally spaced
4. Print the result
5. End the program

PROGRAM:

import numpy as np
a=np.count_nonzero(np.linspace(2,3))
print(a)

OUTPUT:

50

RESULT:

Thus the program is executed successfully and the output is verified


Ex. No. :4(a) Random integer generation
Date:

AIM:

To write a python program to generate an array of random integers within a


specified range

ALGORITHM:

1. Start the program


2. Import numpy library
3. From numpy import random
4. Using randint() get the random integer values by specifying the range as
parameters
5. Print the resultant array
6. End the program

PROGRAM:

import numpy as np
from numpy import random
a=np.random.randint(1,20,10)
print(a)

OUTPUT:

[3 6 14 1 19 10 4 1 11 17]

RESULT:

Thus the program is executed successfully and the output is verified


Ex. No. :4(b) Sine and Cosine of an angle
Date:

AIM:

To write a python program to find sine and cosine of an angle using numpy

ALGORITHM:

1. Start the program


2. Import numpy library
3. sin () and cos() are inbuilt functions in numpy and using them print the
angle values by using np.pi
4. Print the values
5. End the program

PROGRAM:

import numpy as np
x=np.sin(np.pi/2)
y=np.cos(np.pi)
print(x)
print(y)

OUTPUT:

1.0
-1.0

RESULT:

Thus the program is executed successfully and the output is verified


Ex. No. :04(c) Random integer in normal distribution
Date:

AIM:

To write a numpy program to generate a sequence of random numbers in


normal distribution

ALGORITHM:

1. Start the program


2. Import numpy library
3. From numpy import random
4. Using random.normal() with size as parameters, random numbers are
generated.
5. Print the resultant array
6. End the program

PROGRAM:

import numpy as np
from numpy import random
a=np.random.normal(size=3)
print(a)

OUTPUT:

[0.26278459 1048004017 0.90074307]

RESULT:

Thus the program is executed successfully and the output is verified


Ex. No. :04(d) Math functions using numpy
Date:

AIM:

To write a program to perform mathematical functions using numpy for


exponents, log, square roots and cubes of an array

ALGORITHM:

1. Start the program


2. Import numpy library
3. Declare array elements to a variable
4. Pass this variable as parameter to exp(), log(), sqrt() and power() functions
5. Print the result
6. End the program

PROGRAM:

import numpy as np
a=np.array([1, 8, 4])
print(np.exp(a))
print(np.log(a))
print(np.sqrt(a))
print(np.power(a,3))

OUTPUT:

[2.71828183e+00 2.98095799e+03 5.45981500e+01]


[0. 2.07944154 1.3862436]
[1. 2.82842712 2. ]
[1 512 64]

RESULT:

Thus the program is executed successfully and the output is verified


Ex. No. : 05(a) Pandas program to create and display one dimensional

like object

Date :

AIM:

To write a pandas program to create and display a one dimensional


array like object containing an array of data.

ALGORITHM :

1. Start the program

2. Import pandas library as pd

3. Using series function, assign values to a variable

4. Print the variable

5. End the program

PROGRAM :

import pandas as pd

ds=pd.Series([1,3,5,7])

print(ds)

OUTPUT :

0 1

1 3
2 5

3 7

dtype : int64

RESULT :

Thus the program is executed successfully and the output is verified.


Ex. No. : 05 (b) Add, subtract, multiply and divide two pandas series

Date :

AIM :

To write a pandas program to add, subtract, multiply and divide two


pandas series.

ALGORITHM :

1. Start the program


2. Import pandas library as pd
3. Using series function in pandas, assign values to two variables namely a
and b
4. Assign c=a+b
5. Assign d=a-b
6. Assign e=a*b
7. Assign f=a/b
8. Print all the series variables
9. End the program

PROGRAM :

import pandas as pd

a=pd.Series([2,4,6,8])

b=pd.Series([1,3,5,7])

c=a+b

d=a-b;

e=a*b
f=a/b

print(“Series 1)

print(a)

print(“Series 2”)

print(b)

print(“Sum”)

print(c)

print(“Difference”)

print(d)

print(“Product”)

print( e)

print(“Quotient”)

print(f)

OUTPUT :

Series 1

0 2

1 4

2 6

3 8

dtype=int64

Series 2
0 1

1 3

2 5

3 7

dtype=int64

Sum

0 3

1 7

2 11

3 15

dtype=int64

Difference

0 1

1 1

2 1

3 1

dtype=int64

Product

0 2

1 12

2 30

3 56
dtype=int64

Quotient

0 2.0000

1 1.3333

2 1.2000

3 1.1428

dtype=float64

RESULT :

Thus the program is executed successfully and the output is verified


Ex. No. : 05 (c) Create and display of dataframe

Date :

AIM :

To write a pandas program to create and display a dataframe from a


specified dictionary data which has the index labels.

ALGORITHM :

1. Start the program


2. Import pandas library
3. In a variable say exam assign name, score, attempt and qualify as key
values and assign an array of elements to each key.
4. In another variable say label, assign label names
5. Pass the exam and label as parameters to DataFrame function to create a
dataframe and store this in a variable
6. Print the resultant variable
7. End the program

PROGRAM :

import pandas as pd

exam={‘name’ : [‘Joy’,’Diya’,’Anu’,’John’,’Radha’],

‘score’ : [12,9,16,9,20],

‘attempt’ : [1,3,2,3,2],

‘qualify’ : [yes’,’no’,’yes’,’no’,’yes’]}

Labels=[‘a’,’b’,’c’,’d’,’e’]
df=pd.DataFrame(exam,index=Labels)

print(df)

OUTPUT :

name score attempt qualify

a Joy 12 1 yes

b Diya 9 3 no

c Anu 16 2 yes

d John 9 3 no

e Radha 20 2 yes

RESULT :

Thus the program is executed successfully and the output is verified


Ex. No. : 05 (d) Create and display first rows of dataframe

Date :

AIM :

To write a pandas program to create and display the first rows of the
dataframe.

ALGORITHM :

1. Start the program


2. Import pandas library
3. In a variable say exam assign name, score, attempt and qualify as key
values and assign an array of elements to each key
4. In another variable say label, assign label names
5. Pass the exam and label as parameters to DataFrame function to create a
dataframe and store this in a variable
6. Using iloc command print the first 3 rows of the dataframe.
7. End the program

PROGRAM :

import pandas as pd

exam={‘name’ : [‘Joy’,’Diya’,’Anu’,’John’,’Radha’],

‘score’ : [12,9,16,9,20],

‘attempt’ : [1,3,2,3,2],

‘qualify’ : [yes’,’no’,’yes’,’no’,’yes’]}

Labels=[‘a’,’b’,’c’,’d’,’e’]
df=pd.DataFrame(exam,index=Labels)

print(df.iloc[0:3])

OUTPUT :

name score attempt qualify

a Joy 12 1 yes

b Diya 9 3 no

c Anu 16 2 yes

RESULT :

Thus the program is executed successfully and the output is verified


Ex. No. :06 (a) Select specific columns of dataframe

Date :

AIM :

To write a pandas program to select the ‘name’ and ‘scores’ columns


from dataframe

ALGORITHM :

1. Start the program


2. Import pandas library
3. In a variable say exam assign name, score, attempt and qualify as key
values and assign an array of elements to each key
4. In another variable say label, assign label names
5. Pass the exam and label as parameters to DataFrame function to create a
dataframe and store this in a variable
6. Print the columns name and scores from the dataframe
7. End the program

PROGRAM :

import pandas as pd

exam={‘name’ : [‘Joy’,’Diya’,’Anu’,’John’,’Radha’],

‘score’ : [12,9,16,9,20],

‘attempt’ : [1,3,2,3,2],

‘qualify’ : [yes’,’no’,’yes’,’no’,’yes’]}

Labels=[‘a’,’b’,’c’,’d’,’e’]
df=pd.DataFrame(exam,index=Labels)

print(df[[‘name’,’score’]])

OUTPUT :

name score

a Joy 12

b Diya 9

c Anu 16

d John 9

e Radha 20

RESULT :

Thus the program is executed successfully and the output is verified


Ex. No. : 06 (b) Count number of rows and columns in dataframe

Date :

AIM :

To write a pandas program to count the number of rows and columns of


dataframe.

ALGORITHM:

1. Start the program


2. Import pandas library
3. In a variable say exam assign name, score, attempt and qualify as key
values and assign an array of elements to each key
4. In another variable say label, assign label names
5. Pass the exam and label as parameters to DataFrame function to create a
dataframe and store this in a variable
6. Find the length of axes[0] to determine row length
7. Find the length of axes[1] to determine column length
8. Print the row and column length
9. End the program

PROGRAM :

import pandas as pd

exam={‘name’ : [‘Joy’,’Diya’,’Anu’,’John’,’Radha’],

‘score’ : [12,9,16,9,20],

‘attempt’ : [1,3,2,3,2],

‘qualify’ : [yes’,’no’,’yes’,’no’,’yes’]}
Labels=[‘a’,’b’,’c’,’d’,’e’]

df=pd.DataFrame(exam,index=Labels)

rows=len(df.axes[0])

cols=len(df.axes[1])

print(“Rows = “,rows)

print(“Columns = “,cols)

OUTPUT :

Rows = 5

Columns = 4

RESULT :

Thus the program is executed successfully and the output is verified


Ex. No. : 06 (c) Getting all elements in array which are less than n

Date :

AIM :

To write a pandas program to get all elements in array using numpy which
is less than n.

ALGORITHM :

1. Start the program


2. Import numpy as np
3. Using array function pass a two dimensional array as array elements
4. For a variable n assign any number
5. Print the array elements that are lesser than the number
6. End the program

PROGRAM :

import numpy as np

a=np.array([[5.4, 7.1, 9.0],[23.5, 12.9, 4.9],[2.5, 8.9, 1.2]]

n=6

print(“Array elements greater than n=6 are “)

print(a[a<n])

OUTPUT :
[5.4, 4.9, 2.5, 1.2]

RESULT :

Thus the program is executed successfully and the output is verified


Ex. No. : 07 Frequency distribution

Date :

AIM :

To write a pandas program to calculate frequency distribution for a


set of data.

ALGORITHM :

1. Start the program


2. Import pandas library
3. In a variable named df, create a dataframe to store the data elements
4. Using groupby command on ‘A’ calculate size and store it a variable
named count
5. Print count
6. End the program

PROGRAM :

import pandas as pd

df=pd.DataFrame({‘A’ :
[12,67,90,45,89,34,79,45,67,12,48,50,23,47,56,89,79,45,80,57]})

count=fd.groupby([‘A’]).size()

print(count)
OUTPUT :

12 2

23 1

34 1

45 3

47 1

48 1

50 1

56 1

57 1

67 2

79 2

80 1

89 2

90 1

dtype: int64

RESULT :

Thus the program is executed successfully and the output is verified


Ex. No. : 08 Averages

Date :

AIM :

To write a pandas program to calculate mean, standard deviation


and variance for employee database.

ALGORITHM :

1. Start the program


2. Import pandas library
3. Create a dataframe to store employee details with column names
employee id, name, salary and designation
4. Using mean(), std() and dev() the corresponding values are given for
integer values, here salary
5. End the program

PROGRAM :

import pandas as pd

df=DataFrame({‘emp_id’:[ e01, e03, e07, e08, e19, e25, e10, e31, e45, e34];

‘emp_name’:[‘A’,’B’,’C’,’D’,’E’,’F’,’G’,’H’,’I’,’J’],

‘salary’:[12000,18000,30000,70000,50000,55000,45000,25000,30000,60000],

‘designation’:[‘manager’, ‘senior manager’, ‘technician’, ‘stock


holder’, ‘store keeper’, ‘electrician’, ‘senior manager’, ’manager’,
‘technician’]})
print(“Mean”,df.mean())

print(“Standard deviation”,df.std())

print(“Variance”,df.var())

OUTPUT:

Mean 39500.0

Standard deviation 19265.686250

Variance 3.711667e+08

RESULT :

Thus the program is executed successfully and the output is verified


EX NO:09 Programs in variability using python

DATE:

AIM:

To write a python program to find mean, standard deviation and variance


for a set of data using numpy.

ALGORITHM:

1. Start the program


2. Import numpy library
3. Declare and assign array values to a variable
4. Using mean(), std() and var(), store the corresponding values in different
variables
5. Print the variables
6. End the program

PROGRAM:

import numpy as np

array = [24,53,53,36,21,84,64,34,77,54]

print(array)

r1 = np.mean(array)

print(“\nMean :”,r1)

r2 = np.std(array)

print(“SD :”,r2)

r3 = np.var(array)

print(“\nVariance:”,r3)
OUTPUT:

[24,53,53,36,21,84,64,34,77,54]

Mean : 50.0

SD : 20.208908926510603

Variance : 408.4

RESULT:

Thus the program was executed successfully and the output was verified.
Ex. No. :10 Scatterplots using matplotlib

Date:

AIM :

To implement the programs of scatterplots using matplotlib.

ALGORITHM:

1. Start the program


2. Import matplotlib.pyplot
3. Assign array values for x and y
4. Using scatter(), pass x and y as parameters and plot them
5. Print the plot
6. End the program

PROGRAM :

import matplotlib.pyplot as plt

x = [5,7,8,7,2,17,2,9,4,11,12,9,6]

y = [99,86,87,88,111,86,103,87,94,78,77,85,86]

plt.scatter(x,y)

plt.show()
OUTPUT :

RESULT:

Thus the program was executed successfully and the output was verified.
Ex. No. :11 Correlation using matplotlib

Date:

AIM :

To implement programs of correlation using matplotlib.

ALGORITHM:

1. Start the program


2. Import numpy, pandas, sklearn and matplotlib
3. Create a series for x and y
4. Using corr(), find the correlation and store them in a variable
5. Print the variable
6. End the program

PROGRAM:

import sklearn

import numpy as np

import matplotlib.pyplot as plt

import pandas as pd

y = pd.Series([1,2,3,4,3,5,4])

x = pd.Series([1,2,3,4,5,6,7])

correlation = y.corr(x)

print(correlation)
OUTPUT:

0.8603090020146067

RESULT:

Thus the program was executed successfully and the output was verified.
Ex. No. :12 Normal curves

Date:

AIM :

To implement normal curves using python programs.

ALGORITHM:

1. Start the program


2. Import numpy, matplotlib, statistics and norm from scipy
3. Generate a sequence of array for a variable x
4. Find mean and standard deviations for x
5. Plot x with pdf(x,mean, standard deviation)
6. Print the graph

PROGRAMS :

import numpy as np

import matplotlib.pyplot as plt

from scipy.stats import norm

import statistics

x_axis = np.arange(-26,20,0.01)

mean = statistics.mean(x_axis)

sd = statistics.stdev(x_axis)

plt.plot(x_axis,norm.pdf(x_axis,mean,sd))

plt.show()
OUTPUT:

RESULT :

Thus the program is executed successfully and the output is verified.


Ex. No. :13 Program using matplotlib

Date:

AIM:

To write a python program that plots the given values in different types of
plots using matplotlib library.

ALGORITHM:

1. Start the program.


2. Import matplotlib to plot.
3. Declare the input variables (x-axis,y-axis variable).
4. Use plot function (includes other features like axis names , title of the plot,
color of the line, symbols used to denote the plot ,length and width of the
plot).
5. Plot the graph.
6. End the program

PROGRAM:

import matplotlib.pyplot as plt

a = [1, 2, 3, 4, 5]

b = [0, 0.6, 0.2, 15, 10, 8, 16, 21]

plt.plot(a)

plt.plot(b, "or")

plt.plot(list(range(0, 22, 3)))

plt.xlabel('Day ->')

plt.ylabel('Temp ->')
c = [4, 2, 6, 8, 3, 20, 13, 15]

plt.plot(c, label = '4th Rep')

ax = plt.gca()

ax.spines['right'].set_visible(False)

ax.spines['top'].set_visible(False)

ax.spines['left'].set_bounds(-3, 40)

plt.xticks(list(range(-3, 10)))

plt.yticks(list(range(-3, 20, 3)))

ax.legend(['1st Rep', '2nd Rep', '3rd Rep', '4th Rep'])

plt.annotate('Temperature V / s Days', xy = (1.01, -2.15))

plt.title('All Features Discussed')

plt.show()
OUTPUT:

RESULT:
Thus the graph is plotted successfully using Matplotlib and the output
is verified.
Ex. No. :14 Creation of various types of graphs using

R- Programming

Date:

AIM:

To create various types of graphs using R-Programming.

ALGORITHM:

1. Start the program.


2. Declare input variables and values to those variables.
3. Use various types of plot functions to plot the graph in different forms.
4. Plot the graph.
5. End the program

PROGRAM:

i)Plot

x <- c(1, 2, 3, 4, 5)

y <- c(3, 7, 8, 9, 12)

plot(x,y)

ii)Scatter plot

orange <- Orange[, c('age', 'circumference')]

plot(x = orange$age, y = orange$circumference, xlab = "Age",

ylab = "Circumference", main = "Age VS Circumference",

col.lab = "darkgreen", col.main = "darkgreen",


col.axis = "darkgreen")

iii)Line plot

line1 <- c(1,2,3,4,5,10)

line2 <- c(2,5,7,8,9,10)

plot(line1, type = "l", col = "blue")

lines(line2, type="l", col = "red")

iv)Pie chart

library(plotrix)

x <- c(210, 450, 250, 100, 50, 90)

names(x) <- c("Algo", "DS", "Java", "C", "C++", "Python")

pie(x, labels = names(x), col = "white",

main = "Pie chart ", radius = -1,

col.main = "darkgreen")

pie3D(x, labels = names(x), col = "white",

main = "Pie chart in 3D",

labelcol = "darkgreen", col.main = "darkgreen")

v)Bar chart

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 = "Revenue", col = colors)

legend("topleft", regions, cex = 0.7, fill = colors)

barplot(Values, main = "Total Revenue", names.arg = months,

xlab = "Month", ylab = "Revenue", col = colors,horiz =TRUE)

vi)Histogram

v <- c(19, 23, 11, 5, 16, 21, 32, 14,19, 27, 39, 120, 40, 70, 90)

hist(v, xlab = "Weight", ylab ="Frequency",

xlim = c(50, 100),

col = "darkmagenta", border = "pink",

breaks = c(5, 55, 60, 70, 75,80, 100, 140)


OUTPUT:

(i) (ii)

(iii)
(iv)

(v)
(vi)

RESULT:

Thus the program is executed successfully and the output is verified.

You might also like